I have a dataframe like this:
In[1]: df
Out[1]:
A B C D
1 blue red square NaN
2 orange yellow circle NaN
3 black grey circle NaN
and I want to update column D when it meets 3 conditions. Ex:
df.ix[ np.logical_and(df.A=='blue', df.B=='red', df.C=='square'), ['D'] ] = 'succeed'
It works for the first two conditions, but it doesn't work for the third, thus:
df.ix[ np.logical_and(df.A=='blue', df.B=='red', df.C=='triangle'), ['D'] ] = 'succeed'
has exactly the same result:
In[1]: df
Out[1]:
A B C D
1 blue red square succeed
2 orange yellow circle NaN
3 black grey circle NaN
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…