尝试获取组中的第二个最低记录时出错

df.groupby('ID')['date'].nsmallest(2).groupby(level='ID').last()

这是我使用的代码。似乎不起作用,并向我抛出错误。

ID  Date
123  2016-09-11 
123  2018-09-30
123  2017-06-28

我的输出应该是

ID   Date
123  2017-06-28

我不确定为什么我的代码无法正常工作。有人可以帮忙吗?

TypeError: nsmallest() got an unexpected keyword argument 'axis'
ValueError: cannot reindex from a duplicate axis
AttributeError: 'SeriesGroupBy' object has no attribute '_aggregate_item_by_item'

dtype('

slamming123456 回答:尝试获取组中的第二个最低记录时出错

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3113204.html

大家都在问