I have a dataframe df1 :-
I want to achieve this transformation in df1:-
Wherever chcolate has ocurrence count>1 ,Based on first ocurrence assign the brand the same value
>Solution :
try via groupby()+transform():
df['brand'] = df.groupby('chcolate')['brand'].transform('first')
OR
If you want orderwise then use sort_values() first then groupby()+transform():
df['brand'] = df.sort_values('brand').groupby('chcolate')['brand'].transform('first')

