Hi I have a dataframe as below, I need to replace the column value in each group based on the condition using pandas. Please help
Input Data:
Name Thing type flag
Steve Car High NULL
Steve Car Low NULL
Steve Bike Low NULL
Steve Bike Avg X
Steve Plane High NULL
Steve Plane Low NULL
the condition will be :
1. for a given name and thing if type is Low,Avg update the flag as X
2. for a given name and thing if type is High,Avg update the flag as X
Expected output :
Name Thing type flag
Steve Car High NULL
Steve Car Low NULL
Steve Bike Low X
Steve Bike Avg X
Steve Plane High NULL
Steve Plane Low NULL
Tried so far :
df['flag'] = df['flag'].mask((df['type'] == 'Low') | (df['type'] == 'Avg'), 'X').groupby(df(['name','thing'])).transform('any')
Code
df: