Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. >>> import pandas as pd
  2. >>> book1 = pd.read_csv('C:\\scratch\\book1.csv')
  3. >>> book2 = pd.read_csv('C:\\scratch\\book2.csv')
  4. >>> book1
  5. 0:        ID  tran_num  user_id     ...      sequence provider_id  collections
  6. 0   18322    222768        5     ...           3.0          21            1
  7. 1   18323    222769        5     ...           3.0          21            1
  8. 2   18324    222770        5     ...           3.0          21            1
  9. 3   18325    222771        5     ...           3.0          21            1
  10. 4   18326    222772        5     ...           3.0           1            1
  11. 5   18327    222773        5     ...           NaN           1            1
  12. 6   18328    222774        5     ...           3.0           1            1
  13. 7   18329    222775        5     ...           3.0           1            1
  14. 8   18330    222776        5     ...           3.0           1            1
  15. 9   18331    222777        5     ...           3.0           1            1
  16. 10  18332    222778        5     ...           3.0           1            1
  17.  
  18. [11 rows x 13 columns]
  19. >>> book2
  20. 1:       ID  service_code ada_code  ...   submit_on  status  notes
  21. 0  16179          1201     1201  ...         NaN       I    112
  22. 1  16178          1120    D1120  ...         NaN       A    111
  23. 2  16177          1112     1112  ...         NaN       I    463
  24. 3  16176          1111     1111  ...         NaN       I    432
  25. 4  16175          1110    D1110  ...         NaN       A    110
  26. 5  16174           999    D0999  ...         NaN       A    492
  27.  
  28. [6 rows x 10 columns]
  29. >>> comb = book1.merge(book2, on='service_code', how='inner')
  30.  
  31. ---- select all columns ----
  32.  
  33. >>> comb
  34. 3:     ID_x  tran_num  user_id type  ...   taxable_sale  submit_on  status  notes
  35. 0  18322    222768        5    S  ...            NaN        NaN       A    110
  36.  
  37. [1 rows x 22 columns]
  38.  
  39.  
  40. ---- select only desired columns ----
  41.  
  42.  
  43. >>> comb[['service_code','sequence','provider_id','collections','ada_code','description']]
  44. 4:    service_code  sequence     ...       ada_code  description
  45. 0          1110       3.0     ...          D1110    Prophylax
  46.  
  47. [1 rows x 6 columns]
  48.  
  49.  
  50. ---- output to CSV ----
  51.  
  52. >>> pruned = comb[['service_code','sequence','provider_id','collections','ada_code','description']]
  53. >>> pruned.to_csv('C:\\scratch\\output.csv')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement