Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> import pandas as pd
- >>> book1 = pd.read_csv('C:\\scratch\\book1.csv')
- >>> book2 = pd.read_csv('C:\\scratch\\book2.csv')
- >>> book1
- 0: ID tran_num user_id ... sequence provider_id collections
- 0 18322 222768 5 ... 3.0 21 1
- 1 18323 222769 5 ... 3.0 21 1
- 2 18324 222770 5 ... 3.0 21 1
- 3 18325 222771 5 ... 3.0 21 1
- 4 18326 222772 5 ... 3.0 1 1
- 5 18327 222773 5 ... NaN 1 1
- 6 18328 222774 5 ... 3.0 1 1
- 7 18329 222775 5 ... 3.0 1 1
- 8 18330 222776 5 ... 3.0 1 1
- 9 18331 222777 5 ... 3.0 1 1
- 10 18332 222778 5 ... 3.0 1 1
- [11 rows x 13 columns]
- >>> book2
- 1: ID service_code ada_code ... submit_on status notes
- 0 16179 1201 1201 ... NaN I 112
- 1 16178 1120 D1120 ... NaN A 111
- 2 16177 1112 1112 ... NaN I 463
- 3 16176 1111 1111 ... NaN I 432
- 4 16175 1110 D1110 ... NaN A 110
- 5 16174 999 D0999 ... NaN A 492
- [6 rows x 10 columns]
- >>> comb = book1.merge(book2, on='service_code', how='inner')
- ---- select all columns ----
- >>> comb
- 3: ID_x tran_num user_id type ... taxable_sale submit_on status notes
- 0 18322 222768 5 S ... NaN NaN A 110
- [1 rows x 22 columns]
- ---- select only desired columns ----
- >>> comb[['service_code','sequence','provider_id','collections','ada_code','description']]
- 4: service_code sequence ... ada_code description
- 0 1110 3.0 ... D1110 Prophylax
- [1 rows x 6 columns]
- ---- output to CSV ----
- >>> pruned = comb[['service_code','sequence','provider_id','collections','ada_code','description']]
- >>> pruned.to_csv('C:\\scratch\\output.csv')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement