![](/img/trans.png)
[英]How to create a new column based on specific considerations of other columns - Python
[英]How to create rank column in Python based on other columns
你可以做:
df['rank'] = df.groupby('cust_ID')['transaction_count'].rank(ascending=False)
輸出:
cust_ID associate_ID transaction_count rank
0 1234 608 4 1.0
1 1234 785 1 2.0
2 4789 345 2 1.0
3 3456 268 5 1.0
4 3456 725 3 2.0
5 3456 795 1 3.0
請注意,這不僅基於transaction_count
值給出計數,而且還給出交易的等級。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.