【发布时间】:2020-02-05 15:07:41
【问题描述】:
我有 15 个 xlsx 文件,每个文件都有多个工作表。我想动态循环它,使所有工作表和工作簿都在单个数据框中读取。
我曾尝试通过以下方式使用 pd.read_excel
filenames = glob.glob("*.xlsx")
dfList=[]
colnames =['dummy','dummy1','dummy2']
for a in filenames:
df=pd.read_excel(a, sheet_name=None, header = None, encoding = "ISO-8859-1")
dfList.append(df)
df= pd.concat(dfList, axis=0, ignore_index= True)
df.columns= colnames
我运行 pd.concat 时遇到的错误是
TypeError: cannot concatenate object of type "<class 'collections.OrderedDict'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
也试过了
for a in filenames:
df=[pd.read_excel(a, sheet_name=None, header = None, encoding = "ISO-8859-1").values()]
dfList.append(df)
我收到以下错误
TypeError: cannot concatenate object of type "<class 'collections.OrderedDict'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
【问题讨论】:
-
那里给出的代码也不起作用,上面提出的查询中也提到了错误