Using Pandas to Find Minimum Values of Grouped Rows
To get the minimum of column A for each group use transform
df.groupby('group_id')['A'].transform('min')
- focus on just
['col1', 'col2', 'col3']
- see if they are equal to
1
witheq(1)
equivalent to== 1
- see if any are equal to one along
axis=1
withany(1)
- use
loc
to make assignment
anyone = df[['col1', 'col2', 'col3']].eq(1).any(1)
df.loc[anyone, 'A'] = np.nan
numpy equivalent
anyone = (df[['col1', 'col2', 'col3']].values == 1).any(1)
df.A = np.where(anyone, np.nan, df.A)