I'm looking to select rows where state contains the word Traded and trading _book does not start with letters 'E','L','N'
Test_Data = [('originating_system_id', ['RBCL', 'RBCL', 'RBCL','RBCL']),
('rbc_security_type1', ['CORP', 'CORP','CORP','CORP']),
('state', ['Traded', 'Traded Away','Traded','Traded Away']),
('trading_book', ['LCAAAAA','NUBBBBB','EDFGSFG','PDFEFGR'])
]
dfTest_Data = pd.DataFrame.from_items(Test_Data)
display(dfTest_Data)
originating_system_id rbc_security_type1 state trading_book
RBCL CORP Traded LCAAAAA
RBCL CORP Traded Away NUBBBBB
RBCL CORP Traded EDFGSFG
RBCL CORP Traded Away PDFEFGR
Desired output:
originating_system_id rbc_security_type1 state trading_book
RBCL CORP Traded Away PDFEFGR
I though this would do the trick:
prefixes = ['E','L','N']
df_Traded_Away_User = dfTest_Data[
dfTest_Data[~dfTest_Data['trading_book'].str.startswith(tuple(prefixes))] &
(dfTest_Data['state'].str.contains('Traded'))
][['originating_system_id','rbc_security_type1','state','trading_book']]
display(df_Traded_Away_User)
but I'm getting:
ValueError: Must pass DataFrame with boolean values only