pandas : update value if condition in 3 columns are met
Using:
df[ (df.A=='blue') & (df.B=='red') & (df.C=='square') ]['D'] = 'succeed'
gives the warning:
/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:2: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
A better way of achieving this seems to be:
df.loc[(df['A'] == 'blue') & (df['B'] == 'red') & (df['C'] == 'square'),'D'] = 'M5'
You could try this instead:
df[ (df.A=='blue') & (df.B=='red') & (df.C=='square') ]['D'] = 'succeed'
You could try:
df['D'] = np.where((df.A=='blue') & (df.B=='red') & (df.C=='square'), 'succeed')
This answer might provide a detailed answer to the your question: Update row values where certain condition is met in pandas