正如您所知,有一种方法.duplicated
来查找列中的重复项,但我需要的是最后一个重复的元素,它知道我的数据是按日期排序的。你知道吗
以下是列Policy_id
的预期结果Last_dup
:
Id Policy_id Start_Date Last_dup
0 b123 2019/02/24 0
1 b123 2019/03/24 0
2 b123 2019/04/24 1
3 c123 2018/09/01 0
4 c123 2018/10/01 1
5 d123 2017/02/24 0
6 d123 2017/03/24 1
感谢您的帮助和支持!你知道吗
也可以用下面提到的方法完成(不使用Series.duplicated):
使用^{} 或^{} 指定列和参数} :
keep='last'
,然后将True/False
到1/0
映射的反向掩码转换为整数,或使用^{或:
相关问题 更多 >
编程相关推荐