Nov-17-2021, 06:45 AM
I have two excel files, and I wanted to append those files into one. But I also want to add a work book name of excel file into a column "SourceFile".
Error: df = pd.concat([df,new_column], axis=1,ignore_index=True) TypeError: cannot concatenate object of type '<class 'list'>'; only Series and DataFrame objs are valid
File Attached Here
Can anyone please let me know why I am not able to add extra column with workbook name in python???? Or is there any other way we can add that column with workbook name into that???
df = [] for fn in xlsx_files: df.append(pd.read_excel(fn,sheet_name=0)) new_column ={"SourceFile":Path(fn.name)} df = pd.concat([df,new_column], axis=1,ignore_index=True) df.to_csv(os.path.join(path_save, f"combined.csv"), index=False)
Error: df = pd.concat([df,new_column], axis=1,ignore_index=True) TypeError: cannot concatenate object of type '<class 'list'>'; only Series and DataFrame objs are valid
File Attached Here
Can anyone please let me know why I am not able to add extra column with workbook name in python???? Or is there any other way we can add that column with workbook name into that???
Attached Files

