pandas :int32 溢出?无法建立数据透视表 [英] PANDAS: int32 overflow? Can't bulid a pivot table
本文介绍了 pandas :int32 溢出?无法建立数据透视表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 pd.pivot_table() 方法通过旋转用户项目活动数据来创建用户项目矩阵.但是,数据框太大了,我收到了这样的抱怨:
I use the pd.pivot_table() method to create a user-item matrix by pivoting the user-item activity data. However, the dataframe is so large that I got complain like this:
Unstacked DataFrame太大,导致int32溢出
Unstacked DataFrame is too big, causing int32 overflow
有什么解决这个问题的建议吗?谢谢!
Any suggestions on solving this problem? Thanks!
r_matrix = df.pivot_table(values='rating', index='userId', columns='movieId')
推荐答案
一些解决方案:
- 您可以将 Pandas 版本降级到 0.21,这对于具有大尺寸数据的数据透视表没有问题.
- 您可以将数据设置为字典格式,例如
df.groupby('EVENT_ID')['DIAGNOSIS'].apply(list).to_dict()
这篇关于 pandas :int32 溢出?无法建立数据透视表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文