Search code examples
pythonexcelpandasiterablenonetype

How to handle another Excel file in Python


Good Morning. I'm starting with Python and I have a problem. I need to find all .xls files (all have the same header) and merge all into a single DataFrame, so I need to say that the first line of the file should be ignored. The current code I'm using is this:

os.chdir("file folder path")
fileLista = glob.glob('*.xls')
df = list()
for arquivo in fileLista:
    df = df.append(pd.read_excel(arquivo))
    Company= pd.concat(df)
    Company.columns = Company.columns.str.strip()

I am using Glob to return all the .xls extension files, df.append is to merge all the files that have been returned and put inside a DataFrame, Company concat is to form a single file, Company strip is to remove the spaces that it has in the column header. When I run the code it returns me this error: "erro NoneType' object is not iterable"

Can anyone help me with this mistake?


Solution

  • What about this instead?

    fileLista = glob.glob('*.xls')
    Company = pd.DataFrame()
    for arquivo in fileLista:
        df = pd.read_excel(arquivo)
        Company= pd.concat([Company,df])
        Company.columns = Company.columns.str.strip()