Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- originating_system_id rbc_security_type1 state trading_book
- RBCL CORP Traded Away PDFEFGR
- 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)
- ValueError: Must pass DataFrame with boolean values only
- prefixes = ['E','L','N']
- m1 = ~dfTest_Data['trading_book'].str.startswith(tuple(prefixes))
- m2 = dfTest_Data['state'].str.contains('Traded')
- df = dfTest_Data.loc[m1 & m2, ['originating_system_id','rbc_security_type1','state','trading_book']]
- print (df)
- originating_system_id rbc_security_type1 state trading_book
- 3 RBCL CORP Traded Away PDFEFGR
Add Comment
Please, Sign In to add comment