i have the following code...
reader=csv.DictReader(open("test1.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)
i have a csv file which has about 45 cols..
the first column has some names..
except the first column, all others have only 0's and 1's...
and of course, the whole table has some titles as well..
i m trying to read columns from csv file and i need to extract only those cols with 1's
the problem is the output file is empty even though there are a few columns in the table with 1's..
could somebody please help me out.... :( i m stuck terribly..
Title 3003_contact 3003_backbone 3003_sidechain 3003_polar 3003_hydrophobic 3003_acceptor 3003_donor 3003_aromatic
l1 1 1 0 1 1 0 0 0
l1 1 0 1 0 0 0 1 0
l1 1 0 0 0 0 0 0 0
l1 1 0 0 0 1 0 0 1
l1 1 0 0 0 0 0 0 0
l2 1 0 0 0 1 0 0 0
l2 1 0 0 0 0 1 0 0
l3 1 0 0 0 0 0 0 0
l3 1 0 0 0 0 0 1 0
l3 1 0 0 0 0 0 0 1
l3 1 0 0 0 0 0 0 0
l3 1 0 0 0 0 0 0 0
l4 1 0 0 0 0 0 0 0
l4 1 0 0 0 0 0 0 0
l4 1 0 0 0 0 0 0 0