title: Reading a .csv with panda and outputting a single column into a separate .csv file
body: <p>I have a large amount of .txt files, using pandas I can read these and create a data frame for the column I need to output to a separate file. </p>
  
  <p>I have a loop which reads the initial data frames and outputs it to a separate file. However, each new file is immediately overwritten for the next one.</p>
  
  <pre><code>import pandas as pd
  import os
  import csv
  
  #reads all the .txt files I need and outputs as al list
  
  path = '/Users/uni/Desktop/Readtxtpandastest/6'
  
  files=[]
  
  for r, d, f in os.walk(path):
      for file in f:
          if '.txt' in file:
              files.append(os.path.join(r, file))
  f = list(files)
  
  print (f)
  
  
  #Reads the list and creates the new files
  
  for X in files:
          cn=5
          df = pd.read_csv((X), usecols = [cn], index_col=False, header = None)
          print df
          for Y in df:
              df.to_csv ('D', index = False)
  </code></pre>
  
  <p>Each new file is immediately overwritten for the next one.</p>