Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Counting rows for the same date in new column

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading