[英]create new column of incremental number based on 2 categorical columns pandas dataframe
I have a pandas dataframe with the columns username
and phase
.我有一个熊猫数据框,其中包含username
和phase
列。 I want to create a separate column called count
with incremental values.我想用增量值创建一个名为count
的单独列。
The count
will be based on how many times a username
has appeared in a specific phase
. count
将基于username
在特定phase
出现的次数。 How can I accomplish this efficiently?我怎样才能有效地做到这一点? Any suggestion is appreciated.任何建议表示赞赏。
username phase count
0 andrew 1 1
1 andrew 1 2
2 alex 1 1
3 alex 2 1
4 andrew 1 3
5 cindy 3 1
6 alex 2 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.