1

I need to order duplicates in my data frame with a counter value of 1, 2 , 3 etc. The input data frame is like below:

         Key    Amount
         xyz     1000
         xyz1    870
         xyz2    1000
         xyz3    1000
         xyz4    650

and expected output as

         Key    Amount  Duplicate_order
         xyz     1000    1
         xyz1    870     1
         xyz2    1000    2
         xyz3    1000    3
         xyz4    650     1
0

1 Answer 1

1

Using cumcount

df['duplicate_order'] = df.groupby('Amount').cumcount()+1

    Key  Amount  duplicate_order
0   xyz    1000                1
1  xyz1     870                1
2  xyz2    1000                2
3  xyz3    1000                3
4  xyz4     650                1
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.