Python中的熊猫数据aframes出口列表

时间:2021-11-30 04:51:06

I am trying to export a list of pandas dataframes to excel

我正在尝试导出一个熊猫数据名列表以使其优于

list_of_df_to_dump = [df1,df2,...,df100]
list_of_tab_names = ['df1','df2',...,'df100']

writer = ExcelWriter(excel_name + '.xlsx')
for i,j in list_of_df_to_dump,list_of_tab_names:
     i.to_excel(writer,j,index = False)
writer.save()

I get the following error:

我得到以下错误:

TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed

Any ideas as to how this could be fixed or alternative methods to accomplish the same thing? I do not know how long the list will be so doing it manually

有什么方法可以解决这个问题吗?我不知道这个列表会有多长,所以手动操作

1 个解决方案

#1


1  

You have to use zip to iterate through pairs of items from two lists like that. Try the following fix:

您必须使用zip对两个列表中的项目进行迭代。尝试以下解决办法:

list_of_df_to_dump = [df1,df2,...,df100]
list_of_tab_names = ['df1','df2',...,'df100']

writer = ExcelWriter(excel_name + '.xlsx')
for df, tab_name in zip(list_of_df_to_dump, list_of_tab_names):
     df.to_excel(writer, tab_name, index=False)
writer.save()

#1


1  

You have to use zip to iterate through pairs of items from two lists like that. Try the following fix:

您必须使用zip对两个列表中的项目进行迭代。尝试以下解决办法:

list_of_df_to_dump = [df1,df2,...,df100]
list_of_tab_names = ['df1','df2',...,'df100']

writer = ExcelWriter(excel_name + '.xlsx')
for df, tab_name in zip(list_of_df_to_dump, list_of_tab_names):
     df.to_excel(writer, tab_name, index=False)
writer.save()