I have a master table that contains some fields. I want to join it with a bunch of other csvs.
Current data looks like:
File 1:
Key Attrib1 Attrib2 Attrib3 Attrib4
File 2:
Key Attrib5
File 3:
Key Attrib6
I want my final output to look like:
Key Attrib1 Attrib2 Attrib3 Attrib4 Attrib5 Attrib6, etc.
Not all the files contain the all of the keys.
Current Code:
master = "in.csv"
file1 = "file.csv"
file2 = "file2.csv"
prime = list()
D1 = {}
with open(master) as f:
for k in csv.reader(f):
prime.append(k[0])
for k in prime:
with open(file1,'r') as csvfile:
rd = csv.reader(csvfile,delimiter=",")
for row in rd:
if row[0] ==k:
D1 = dict((row[0],row[1]) for rows in rd)
with open(file2,'r') as csvfile:
rd = csv.reader(csvfile,delimiter=",")
for row in rd:
if row[0] ==k:
D1 = D1+dict((row[0],row[1]) for rows in rd)
I think this does close if not exactly what you want: