【发布时间】:2018-11-19 19:36:01
【问题描述】:
我有一个可变长度的数据框列表,我想将每个数据框列表转换为每个 Excel 工作表。
这是我的代码:
for i in range(1, len(dfs)):
frames = {'sheetName_i' : dfs[i]}
for sheet, df in frames.items():
dfs[i].to_excel(writer, index=False)
#df is the whole dataframe whereas dfs is the list of df
我的输出中只有最后一个列表。 有什么方法可以将所有列表转换为单独的 Excel 工作表?
我使用了您的建议如下:
for i, df in enumerate(dfs, 1):
for n in group: #containe the names that I want to name the sheets amd the names equal to the number of sheets.
df.to_excel(writer, index=False, sheet_name=n.format(i))
工作表名称已更改为我需要的名称。尽管每张表的数据相似,但会丢失一些数据内容,并且将一些数据合并到一张表中,并且在每张表中重复相同的数据。 有什么办法可以得到正确的输出。
很高兴听到一些建议。非常感谢您。
【问题讨论】: