I want to check if on any dataframe
row a given number of columns has any of a set of values (different sets for different columns) and assign a boolean
accordingly - I think I might need a combination of apply()
and any()
but not quite hitting it exactly:
So, for dataframe:
bank_dict = {'Name' : ['A', 'B', 'C', 'D', 'E'],
'Type' : ['Retail', 'Corporate', 'Corporate', 'Wholesale', 'Retail'],
'Overdraft': ['Y', 'Y', 'Y', 'N', 'N'],
'Forex': ['USD', 'GBP', 'EUR', 'JPY', 'GBP']}
With truth list:
truth_list = [bank_df['Type'].isin(['Retail']), bank_df['Overdraft'].isin(['Yes']), bank_df['Forex'].isin(['USD', 'GBP'])]
The resultant df should look like:
Name Type Overdraft Forex TruthCol
0 A Retail Y USD 1
1 B Corporate Y GBP 1
2 C Corporate Y EUR 1
3 D Wholesale N JPY 0
4 E Retail N GBP 1
Thanks,