Skip to content

Instantly share code, notes, and snippets.

@ardinusawan
Created April 7, 2017 21:09
Show Gist options
  • Save ardinusawan/d4ae52c6693e108504531e57ba7064f3 to your computer and use it in GitHub Desktop.
Save ardinusawan/d4ae52c6693e108504531e57ba7064f3 to your computer and use it in GitHub Desktop.
This python program using pandas for merge multiple (not just 2!) csv file based on primary key
# http://pandas.pydata.org/pandas-docs/stable/merging.html
# Search on 'Brief primer on merge methods (relational algebra)'
import pandas as pd
csv_input = pd.read_csv('./file_A.csv')
df = pd.DataFrame(csv_input)
csv_input2 = pd.read_csv('./file_B.csv')
df2 = pd.DataFrame(csv_input2)
combined = pd.merge(csv_input, csv_input2, on='Primary Key')
combined.to_csv('output.csv', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment