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('