Skip to content

Instantly share code, notes, and snippets.

@haoshuai999
Created August 1, 2019 14:57
Show Gist options
  • Save haoshuai999/76d183aa932ebdb3956c6cda600d2685 to your computer and use it in GitHub Desktop.
Save haoshuai999/76d183aa932ebdb3956c6cda600d2685 to your computer and use it in GitHub Desktop.
Concatenate two CSV files
import csv
import pandas as pd
totalEnroll = pd.read_csv("Total-Enrollment.csv")
interEnroll = pd.read_csv("Inter-Enrollment.csv")
totalArray = []
for rowtotal in totalEnroll.iterrows():
for rowinter in interEnroll.iterrows():
if str(rowinter[1][0]) in rowtotal[1][0]:
totalArray.append((str(rowinter[1][0]),rowtotal[1][0],rowtotal[1][1],rowinter[1][1]))
df = pd.DataFrame(totalArray)
df.to_csv(path_or_buf='output.csv', header=True, index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment