title: How to covert multiple .txt files into .csv file in Python
body: <p>I'm trying to covert multiple text files into a single .csv file using Python. My current code is this:</p>
  <pre><code>import pandas
  import glob
  
  #Collects the files names of all .txt files in a given directory.
  file_names = glob.glob(&quot;./*.txt&quot;)
  
  #[Middle Step] Merges the text files into a single file titled 'output_file'.
  with open('output_file.txt', 'w') as out_file:
      for i in file_names:
          with open(i) as in_file:
              for j in in_file:
                  out_file.write(j)
  
  #Reading the merged file and creating dataframe.
  data = pandas.read_csv(&quot;output_file.txt&quot;, delimiter = '/')
    
  #Store dataframe into csv file.
  data.to_csv(&quot;convert_sample.csv&quot;, index = None)
  </code></pre>
  <p>So as you can see, I'm reading from all the files and merging them into a single .txt file. Then I convert it into a single .csv file. Is there a way to accomplish this without the middle step? Is it necessary to concatenate all my .txt files into a single .txt to convert it to .csv, or is there a way to directly convert multiple .txt files to a single .csv?</p>
  <p>Thank you very much.</p>