我有一个pandas数据帧,如下所示:
userid name date
1 name1 2016-06-04
1 name2 2016-06-05
1 name3 2016-06-04
1 name1 2016-06-06
2 name23 2016-06-01
2 name2 2016-06-01
3 name1 2016-06-03
3 name6 2016-06-03
3 name12 2016-06-03
3 name65 2016-06-04
所以,我只想在第一个日期事件之前保留用户行,并删除其余的行。在
最终df如下:
^{pr2}$时间列中数据点的type()
是datetime.date
因此,这些任务将涉及grouping with respect to userid
,sorting according to the date
,然后retaining only the rows with first(/earliest) date
。在
您可以先按列} 对} ^{} 对
date
按^{DataFrame
排序,然后用^{DataFrame
进行排序-获取第一个值所在的所有行:相关问题 更多 >
编程相关推荐