问题描述
我有一个这样的数据集:
Fruit Qty
0 Apple 1
1 Orange 3
2 Pear 7
3 Orange 1
4 Pear 23
5 Lemon 5
我试图获得这个:
Fruit Qty
0 Apple 1
1 Orange 1
2 Pear 23
3 Lemon 5
所以我想通过“水果”列中最后一次出现来过滤我的数据集的行。
1楼
IIUC drop_duplicates
s=df.drop_duplicates('Fruit',keep='last')
s
Fruit Qty
0 Apple 1
3 Orange 1
4 Pear 23
5 Lemon 5