Advertisement
cd62131

merge csv with pandas

Dec 15th, 2017
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import pandas as pd
  3. f1 = pd.read_csv(
  4.     'file1.csv',
  5.     header=0,
  6.     names=['date','ringo','mikan','banana'])
  7. f2 = pd.read_csv(
  8.     'file2.csv',
  9.     header=0,
  10.     names=['date','chicken','beef','pork'])
  11. f3 = f1.merge(f2, how='outer').sort_values(by='date')
  12. f3.to_csv(
  13.     'file3.csv',
  14.     header=['','りんご','みかん','バナナ','鶏肉','牛肉','豚肉'],
  15.     index=None,
  16.     float_format='%.0f',
  17.     na_rep='#N/A')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement