trying to add a boolean column to a df based on two mutually exclusive conditions:
df['Type'] == 'CMBX'
df['SubType'].isin(['EM','NAHY'])
they work separately
df['Px Quoted'] = np.where(df['Type'] =='CMBX', True, False)
df[df['Type']=='CMBX'].head(5)
Out[72]:
Batch Type SubType Px Quoted
0 NaN CMBX True
1 NaN CMBX True
2 NaN CMBX True
3 NaN CMBX True
4 NaN CMBX True
or
df['Px Quoted'] = np.where(df['SubType'].isin(['EM','NAHY']), True, False)
df[df['SubType']=='EM'].head(5)
Out[74]:
Batch Type SubType Px Quoted
21 NY1530 CDX EM True
29 NY1530 CDX EM True
36 NY1530 CDX EM True
43 NY1530 CDX EM True
50 NY1530 CDX EM True
but the following does not
df['Px Quoted'] = np.where(df['Type'] =='CMBX' or df['SubType'].isin(['EM','NAHY']), True, False)
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
not sure why it is ambiguous as Type CMBX cannot contain any of Subtype ['EM','NAHY']
Any ideas? is that because its Subtype is blank?