python - 熊猫合并没有给出预期的结果
问题描述
我试图合并两个数据框 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
我在这里做错什么了吗?请帮忙。提前致谢!
解决方案
推荐阅读
- c++ - 如何使用 fmt 库用十进制逗号格式化浮点数?
- sql-server - 过程数据输入临时表
- elixir - 在混合文件的别名内运行迁移命令两次
- typescript - 如果我的函数返回另一个函数,如何检查“缺少的函数返回类型”?
- javascript - 如何在反应原生FlatList中实现onEndReached()和onRefresh()“水平”反应原生
- django - 如何在基于类的列表视图上创建搜索功能?
- c++ - 如何在 C++ 中使用智能指针实现接口隔离原则?
- c# - WebForms 在帖子中不断显示事件验证错误
- html - 将文本悬停在图像上时缩放图像
- c++ - 我正在尝试使用 (setw) 完善我的输出,但如果我输入的值在范围内不同,则它无法正常工作