我正在尝试合并两个数据帧 df1 和 df2,只获取“column1”具有相同值的行,并将结果数据帧写入 excel。
代码:
#some other code above
if df1.empty == False and df2.empty == False:
common_df = pd.merge(df1, df2, how='inner', on='column1')
with pd.ExcelWriter('/usr/outfile.xlsx') as writer:
common_df.to_excel(writer, sheet_name='common', index=False)
else:
pass
在运行我的代码时,我在 df1 中有 20000 行,在 df2 中有 300000 行。
我的 df1 和 df2 的几行。
df1:
如果一切顺利,我的 common_df 中可能有大约 10000 行,应该可以轻松写入 Excel 表。但是合并步骤返回了一些无法写入excel的大量数据。
错误:
File "C:\Python3\lib\site-packages\pandas\io\formats\excel.py", line 804, in write
f"This sheet is too large! Your sheet size is: {num_rows}, {num_cols} "
ValueError: This sheet is too large! Your sheet size is: 10325130, 9 Max sheet size is: 1048576, 16384
我在这里做错了什么吗?请帮忙。提前致谢!