Pandas Groupby错误仅发生在大型数据集中
我使用这样的代码在gropus中选择具有最大值的行:
set_f = set.loc[set.reset_index().groupby(['Scan Number'])['dda246displmils'].idxmax()]
与数据集OD〜1M行相机,但是当尝试将38M行分组时,我会遇到此错误:
keyError:'将列表类似于.loc或.loc或[]不再支持任何缺失的标签,请参见 https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlex-listlike'
是什么原因?更大的数据集还有其他选择吗?
谢谢, 宝琳娜
I use such code to select rows with max value in gropus:
set_f = set.loc[set.reset_index().groupby(['Scan Number'])['dda246displmils'].idxmax()]
and this works perfectly fine with dataset od ~1M rows but i get this error when try to group 38M rows:
KeyError: 'Passing list-likes to .loc or [] with any missing labels is no longer supported, see https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike'
What is the reason? Is there any other option for bigger dataset?
Thanks,
Paulina
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您要选择由
reset_index
创建的新创建的原始索引值,因此提出错误。解决方案在
loc
之前重新分配:Problem is you want select original index values by new created by
reset_index
, so raise error.Solution is reassign back before
loc
: