PV8
PV8

Reputation: 6260

Error while loading multiple excel sheets into pandas

I try to load multiple excel files with multiple excel sheets into a pandas dataframe, right now I am running:

import pandas as pd
import glob

files = glob.glob(r'C:\...\Data\*.xlsx')
dfs = pd.read_excel(f,sheet_name=None) for f in files]
df = pd.concat(dfs, ignore_index=True)

The none parameter makes sure that I load all sheets in every excel, but i get the error:

TypeError: cannot concatenate object of type ', only Series and Dataframe objs are valid.

How can I solve this?

Upvotes: 0

Views: 210

Answers (1)

jezrael
jezrael

Reputation: 862431

Here is necessary join DataFrames in first list comprehension, because if pass sheet_name=None get Orderdict of DataFrames:

dfs = [pd.concat(pd.read_excel(f,sheet_name=None)) for f in files]
df = pd.concat(dfs, ignore_index=True)

Upvotes: 1

Related Questions