Skip to content
Advertisement

Pandas generate numeric sequence for groups in new column

I am working on a data frame as below,

JavaScript

I want to create a new column with the sequence value for Column B subgroups based on Column A groups like below

JavaScript

I tried this , but does not give me desired output

JavaScript

Advertisement

Answer

IIUC, I think you want something like this:

JavaScript

Output:

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