Issue
I would like to create a new column. Column should count all rows for the same date.
in:
| date |
----------------
| 12.02.2000 |
| 12.02.2000 |
| 12.02.2000 |
| 12.02.2000 |
| 12.02.2000 |
| 13.02.2000 |
| 14.02.2000 |
| 14.02.2000 |
out:
| date | Cumulative
---------------|-----------
| 12.02.2000 | 1
| 12.02.2000 | 2
| 12.02.2000 | 3
| 12.02.2000 | 4
| 12.02.2000 | 5
| 13.02.2000 | 1
| 14.02.2000 | 1
| 14.02.2000 | 2
Solution
You want to use cumcount
after a groupby
df.assign(Cumulative=df.groupby('date').cumcount()+1)
date Cumulative
0 12.02.2000 1
1 12.02.2000 2
2 12.02.2000 3
3 12.02.2000 4
4 12.02.2000 5
5 13.02.2000 1
6 14.02.2000 1
7 14.02.2000 2
Answered By - piRSquared
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.