我试图添加一个基于两列的索引(在我的例子中是单个和集群)+第三列的排序值(totalPrice)
所以我有一个数据集,有三列-个体、集群和totalPrice。你知道吗
individual cluster totalPrice totalTripDurationMinutes
0 9710556 1 180.82 140
1 9710556 0 202.32 145
2 9710556 0 180.82 140
3 9710535 7 729.44 460
4 9710535 7 729.44 640
5 9710535 7 702.60 355
6 9710535 7 685.82 300
7 9710535 7 685.82 480
8 9710535 7 669.44 520
9 9710535 7 669.44 580
10 9710535 7 669.44 700
我想做的是,对于每个个体和每个集群,我想找到totalPrice条目的数量,这些条目由当前totalPrice控制。 结果如下所示:
individual dominationCount cluster totalPrice totalTripDurationMinutes
0 9710556 0 1 180.82 140
1 9710556 0 0 202.32 145
2 9710556 1 0 180.82 140
3 9710535 0 7 729.44 460
4 9710535 0 7 729.44 640
5 9710535 1 7 702.60 355
6 9710535 2 7 685.82 300
7 9710535 2 7 685.82 480
8 9710535 3 7 669.44 520
9 9710535 3 7 669.44 580
10 9710535 3 7 669.44 700
你知道怎么在熊猫身上做吗?你知道吗
您可以定义一个名为
check_price
的函数:然后使用groupby和transform
使用^{} 和
methos='dense'
并减去1
:这里有一个非常复杂的方法:
结果是:
相关问题 更多 >
编程相关推荐