I think you can try other alternatives - compared to numpy in1dor perhaps str.contains, but for me all 3 approaches work very well (but mine python: 2.7.11.final.0, pandas: 0.18.0and numpy: 1.10.4):
print df
result
0 Action Taken
1 Action Taken Action Taken
2 Action
3 Something else
print df['result']=='Action Taken'
0 True
1 False
2 False
3 False
Name: result, dtype: bool
print np.in1d(df['result'],'Action Taken')
[ True False False False]
print df['result'].str.contains('Action Taken')
0 True
1 True
2 False
3 False
Name: result, dtype: bool
df['closed_item'] = np.where(df['result']=='Action Taken', 1, 0)
df['closed_item1'] = np.where(np.in1d(df['result'],'Action Taken'), 1, 0)
df['closed_item2'] = np.where(df['result'].str.contains('Action Taken'), 1, 0)
print df
result closed_item closed_item1 closed_item2
0 Action Taken 1 1 1
1 Action Taken Action Taken 0 0 1
2 Action 0 0 0
3 Something else 0 0 0
source
share