Team,
2 things i am trying to do as per below code
1) write data in column 2,3,4 and 8 of file1 to a new file.
2) data in 1st column(copied in new file)should be searched file2. if found,pick the data in 3rd column of same row of file 2 and write the same to the new column of new file.
point 1 is working fine..finding issue in getting output as per 2nd point
import csv
f1 = csv.reader(open("C:/Users/file1.csv","rb"))
f2 = csv.writer(open("C:/Users/newfile.csv","wb"))
f3 = csv.reader(open("C:/Users/file2.csv","rb"))
for row in f1:
if not row[0].startswith("-"):
f2.writerow((row[1],row[2],row[3],row[7]))
var1 = row[1]
for row in f3:
if var1 in row:
f2.append(row[2])
f3can be anywhere? Not in a particular column?