hi, I'll explain my whole problem:
I have 2 csv files:
- project-table.csv (has about 50 columns)
- interaction-matrix.csv (has about 45 columns)
I want to append the string in col[43]
from project-table.csv with string in col[1]
of interaction-matrix.csv with a dot(.
) in between both the strings
next,
- interaction-matrix.csv has a set of headers..
- its 1st col will now have the appended string after doing what I've mentioned above
- all other remaining columns have only 0's and 1's
- I'm supposed to extract only those columns with 1's from this interaction-matrix.csv and copy it to a new csv file... (with the first column intact)
this is the code i ve come up with...
I'm getting an error with the keepcols
line...
import csv
reader=csv.reader(open("project-table.csv","r"))
writer=csv.writer(open("output.csv","w"),delimiter=" ")
for data in reader:
name1=data[1].strip()+'.'+data[43].strip()
writer.writerow((name1, None))
reader=csv.DictReader(open("interaction-matrix.csv","r"),[])
allrows = list(reader)
keepcols = [c for c in allrows[0] if all(r[c] != '0' for r in allrows)]
print keepcols
writer=csv.DictWriter(open("output1.csv","w"),fieldnames='keepcols',extrasaction='ignore')
writer.writerows(allrows)
this is the error i get:
Traceback (most recent call last):
File "prg1.py", line 23, in ?
keepcols = [c for c in allrows[0] if all([r[c] != '0' for r in allrows])]
NameError: name 'all' is not defined
project table and interaction-matrix both have the same data in their respective 1st columns .. so i just appended col[43] of prj-table to col[1] of the same table itself...