Reputation: 421
I have below pandas data frame in python.
Looking for below output:
Based upon group of last column I need to pick and repeat first value from and in middle column.
Upvotes: 0
Views: 59
Reputation: 150735
Try:
df['col1'] = df['col1'].mask(df['col2'].duplicated()).ffill()
Or:
df['col1'] = df.groupby('col2')['col1'].transform('first')
Upvotes: 2