title: How can I take each part of a file name and insert it into a table separately?
body: <p>I've written a script that calculates a value for different genes in an organism. I would like to get out a csv file that has the columns 'Species ID', 'locus tag' and then the value itself.</p>
  <p>I'm new to Python and I can't quite figure out how I would do this? An example of a file name is:</p>
  <p>NC_000117.1+CT_001.txt</p>
  <p>and each bit before and after the + is different. For reference, the bit before is the species ID and the bit after the + is the locus tag. I have around 6000 of these files and they're pretty small, so it shouldnt take too long to process!</p>
  <p>This is my code so far:</p>
  <pre><code>import os
  import io
  import glob
  import pandas as pd
  import csv
  work_dir = &quot;User/...&quot;
  for path in glob.glob(os.path.join(work_dir, &quot;*.txt&quot;)):
      with io.open(path, mode=&quot;r&quot;, encoding=&quot;utf-8&quot;) as dir:
          genome = dir.read()
  
      GC3_list = list()
      locus_list = list()
  
  #calculates the total base number of each txt file
      total_base = len(genome)
      # print(&quot;Total no of bases:&quot; + str(total_base))
  
  #counts number of g and c bases at every 3rd position
      g = genome[::3].count('g')
      c = genome[::3].count('c')
      # print(&quot;Number of G bases:&quot;+str(g))
      # print(&quot;Number of C bases:&quot;+str(c))
  
  #calculates final GC3 content in %
      GC3 = ((g+c)/total_base) * 100
      #print(&quot;GC3 content in % :&quot; + str(GC3))
      GC3_list.append(GC3)
  
  #loci names taken from file
      loci = os.path.basename(path).replace('.txt', &quot;&quot;)
      locus_list.append(loci)
  
  df = pd.DataFrame({'Locus tag':locus_list,
                    'GC3 %': GC3_list})
  
  df.to_excel('output')
  </code></pre>