0

I'm making a program that lists files from the network folder and if it meets the naming standards add it to the list of candidate files.
I am getting this error:

AttributeError: 'DataFrame' object has no attribute 'append'

I made this code:

import os
import shutil
from unicodedata import normalize
import pandas as pd

ORIGIN_DIR = os.path.join(os.path.expanduser("~"), "Downloads")

# Listing network folder files
list_files = pd.DataFrame(columns=["nome_arquivo", "hora_modf"])
for item in os.listdir(ORIGIN_DIR):
    file_name = os.path.join(ORIGIN_DIR, item)
    if os.path.isfile(file_name):
        # If it meets the naming standards, add it to the candidate file list
        name_normalized = normalize("NFKD", item.upper()).encode("ascii", "ignore").decode("ascii")
        if name_normalized.endswith(".XLSX") and name_normalized.startswith("GESTAO") and "EMPURRADA" \
                in name_normalized and not name_normalized.startswith("~$"):
            row = {
                "nome_arquivo": item,
                "hora_modf": (os.path.getmtime(file_name))
            }
            list_files = list_files.append(row, ignore_index=True)

I already tried to use list_files.concat() but I had no success
Sorry for any english mistakes, I used google translate.

  • 2
    You should never `append` to a DataFrame in a loop. This method was removed because it was improperly used. Collect in a python list and instantiate a DataFrame or `concat` **once** in the end. – mozway Aug 10 '23 at 20:38

0 Answers0