title: append a particular column from a csv file to another using python
body: <p>I'll explain my whole problem:<br>
  I have 2 csv files:</p>
  
  <ul>
  <li>project-table.csv  (has about 50 columns)  </li>
  <li>interaction-matrix.csv  (has about 45 columns)  </li>
  </ul>
  
  <p>I want to append the string in <code>col[43]</code> from project-table.csv with string in <code>col[1]</code> of interaction-matrix.csv with a dot(<code>.</code>) in between both the strings</p>
  
  <p>next,</p>
  
  <ul>
  <li>interaction-matrix.csv has a set of headers..  </li>
  <li>its 1st col will now have the appended string after doing what I've mentioned above  </li>
  <li>all other remaining columns have only 0's and 1's   </li>
  <li>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)</li>
  </ul>
  
  <p>this is the code i ve come up with...  </p>
  
  <p>I'm getting an error with the <code>keepcols</code> line...</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>this is the error i get:  </p>
  
  <pre><code>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
  </code></pre>
  
  <p>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...</p>