How to set same transaction number if there is same time stamp in pandas data frame

Viewed 22

I have a data frame

dataframe

if time stamp of an instance is same with the time stamp of a second instance, I need to create a new column and set the same transaction number for both instances

I have tried using np.where and isin but I was only able to set two values

1 Answers

IIUC, use ngroup to get an id per group:

df['number'] = df.groupby(['name', 'timestamp']).ngroup()
Related