Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying ton concat excel files with pandas but I get this error message "AttributeError: 'DataFrame' object has no attrctionibute 'concat'"
My code is the following:
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")
Thanks a lot by advance!
concat
is a method from the pandas library, not a class method of a pandas.DataFrame
. What that means, is that you can't use df1.concat(df2)
, but as stated in the documentation, you need to use it as such:
df_concat = pd.concat([df1, df2])
so in your case, it would look like:
final19 = pd.concat([final19,step19])
final18 = pd.concat([final18,step18])
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.