g = df.groupby(['unique_id', 'period_id'], as_index=False)
g.transform('max')
df.update(g.transform('max'))
g.nth(0)
Pandas - remove duplicate rows except the one with highest value from another column