Skip to content
Advertisement

Extract duplicity without rearranging the column and find cumsum in python

I have a dataset with 4000 rows, where I have the duplicate rows(e.g. 2, 3, 4 times). I want to find the cumsum of the duplicates over time.

I have used this code to assign the number of duplicity. But it has rearranged the position of ID

JavaScript

Output

JavaScript

whereas I want to add the duplicity and the ID remains same position.

JavaScript

How to find cumsum of duplicity over time? Thank you.

Input data:

JavaScript

Advertisement

Answer

Use groupby and transform:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement