Guest User

Untitled

a guest
Jul 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. Test_Data = [('originating_system_id', ['RBCL', 'RBCL', 'RBCL','RBCL']),
  2. ('rbc_security_type1', ['CORP', 'CORP','CORP','CORP']),
  3. ('state', ['Traded', 'Traded Away','Traded','Traded Away']),
  4. ('trading_book', ['LCAAAAA','NUBBBBB','EDFGSFG','PDFEFGR'])
  5. ]
  6. dfTest_Data = pd.DataFrame.from_items(Test_Data)
  7. display(dfTest_Data)
  8.  
  9. originating_system_id rbc_security_type1 state trading_book
  10. RBCL CORP Traded LCAAAAA
  11. RBCL CORP Traded Away NUBBBBB
  12. RBCL CORP Traded EDFGSFG
  13. RBCL CORP Traded Away PDFEFGR
  14.  
  15. originating_system_id rbc_security_type1 state trading_book
  16. RBCL CORP Traded Away PDFEFGR
  17.  
  18. prefixes = ['E','L','N']
  19. df_Traded_Away_User = dfTest_Data[
  20. dfTest_Data[~dfTest_Data['trading_book'].str.startswith(tuple(prefixes))] &
  21. (dfTest_Data['state'].str.contains('Traded'))
  22. ][['originating_system_id','rbc_security_type1','state','trading_book']]
  23. display(df_Traded_Away_User)
  24.  
  25. ValueError: Must pass DataFrame with boolean values only
  26.  
  27. prefixes = ['E','L','N']
  28.  
  29. m1 = ~dfTest_Data['trading_book'].str.startswith(tuple(prefixes))
  30. m2 = dfTest_Data['state'].str.contains('Traded')
  31.  
  32. df = dfTest_Data.loc[m1 & m2, ['originating_system_id','rbc_security_type1','state','trading_book']]
  33. print (df)
  34. originating_system_id rbc_security_type1 state trading_book
  35. 3 RBCL CORP Traded Away PDFEFGR
Add Comment
Please, Sign In to add comment