Created
April 7, 2017 21:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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