I have 2 csv files that I am generating via python. The records are below (a.csv and b.csv). b.csv has 2 rows and the values in second row can be duplicates. I want to have a result like final.csv. How can I do that?
I tried below code but that's not right. I am not doing the right comparison. Any help would be great.
a.csv
"all","1","1Gi","4","8Gi"
"als","0","0","100m","128Mi"
"awx","6","9Gi","20","32Gi"
"cho-1","9","9728Mi","15","20Gi"
"cho-2","12250m","15395Mi","20","24Gi"
b.csv
"all","ABC"
"als","ABC"
"awx","DPL"
"cho-1","ABC"
"cho-2","ABC"
"cho-3","ABC"
I want to create one file out of both like below
final.csv
"all","1","1Gi","4","8Gi","ABC"
"als","0","0","100m","128Mi","ABC"
"awx","6","9Gi","20","32Gi","DPL"
"cho-1","9","9728Mi","15","20Gi","ABC"
"cho-2","12250m","15395Mi","20","24Gi","ABC"
my code:
csv1 = csv.reader(open("reports/a.csv", "r"))
csv2 = csv.reader(open("reports/b.csv", "r"))
s=[]
while True:
try:
line1 = csv1.next()
line2 = csv2.next()
if (line1[0] == line2[0]):
s.append([line1[1], line2[0], line2[1], line2[2], line2[3], line2[4]])
else:
s.append(["NA", line2[0], line2[1], line2[2], line2[3], line2[4]])
except StopIteration:
break