我正在尝试用 pandas 连接 excel 文件,但我收到此错误消息“AttributeError:‘DataFrame’对象没有 attrctionibute ‘concat’”
我的代码如下:
def action():
all_files = filedialog.askopenfilename(initialdir = "/",
multiple=True,
title="select",
filetypes=(
("all files", "*.*"),
("Excel", "*.xlsx*")))
dossier=filedialog.askdirectory()
final19=pd.DataFrame()
final18=pd.DataFrame()
first=True
for f in all_files:
step19=pd.read_excel(f,sheet_name='2019')
step18=pd.read_excel(f,sheet_name='2018')
if first:
first=False
fina19=step19
final18=step18
else:
final19 = final19.concat(step19)
final18 = final18.concat(step18)
final19.to_excel(dossier+'\\Filefinal.xlsx',sheet_name='19',index=False)
final18.to_excel(dossier+'\\Filefinal.xlsx',sheet_name='18',index=False)
tkinter.messagebox.showinfo("Files", "ready")
提前非常感谢!
concat
是 pandas 库中的方法,而不是 pandas.DataFrame
的类方法。这意味着您不能使用df1.concat(df2)
,但如文档中所述,您需要这样使用它:
df_concat = pd.concat([df1, df2])
所以在你的情况下,它看起来像:
final19 = pd.concat([final19,step19])
final18 = pd.concat([final18,step18])