Created
June 7, 2017 21:12
-
-
Save spellancer/af0255604f2dfad7a995d1437e03722a to your computer and use it in GitHub Desktop.
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
import csv | |
from collections import OrderedDict | |
with open('b.csv', 'rb') as f: | |
r = csv.reader(f) | |
dict2 = {row[0]: row[1:] for row in r} | |
with open('a.csv', 'rb') as f: | |
r = csv.reader(f) | |
dict1 = OrderedDict((row[0], row[1:]) for row in r) | |
result = OrderedDict() | |
for d in (dict1, dict2): | |
for key, value in d.iteritems(): | |
result.setdefault(key, []).extend(value) | |
with open('ab_combined.csv', 'wb') as f: | |
w = csv.writer(f) | |
for key, value in result.iteritems(): | |
w.writerow([key] + value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment