title: How to concencate two tab separated data frames for each unique subfolder
body: <p>I'm facing a puzzling thing.</p>
  <pre><code>C:// Total / a12 / a12.tsv
  C:// Total / a12 / a12_1.tsv
  
  C:// Total /b12 / b12.tsv
  C:// Total /b12 / b12_1.tsv
  </code></pre>
  <p>As you can tell, I have a directory 'Total' and sub-directories 'a12' and 'b12' respectively. In each of the sub-directories, I have exactly two .tsv files. My aim is to load each one successfully into two pandas data frame and concencate the data frame into one, and output the output as a file:</p>
  <pre><code>C: // Total / a12 / a12_combined.tsv
  C: // Total / b12 / b12_combined.tsv
  </code></pre>
  <p>I'd like to combine a12.tsv and a12_1.tsv into a12_combined.tsv in the folder a12 and same with b12_combined.tsv in b12</p>
  <p>In reality, I have twenty-six different sub-folders to iterate through. I tried using glob.glob to scan each recursively, but it ended up creating a master folder combining all of the four dataframes into one.</p>
  <p>This is all I have so far:</p>
  <pre><code>import glob as glob
  import pandas as pd
  file = glob.glob('Total/**/*.tsv')
  
      df = pd.concat([pd.read_csv(f, error_bad_lines=(False), sep = '\t') for f in file])
  
      print(file)
  
      df.to_csv (&quot;merged.tsv&quot; , sep = '\t')
  </code></pre>
  <p>I'd also like to name the output of each file as &quot;.tsv file name _ combined&quot; if that makes sense. If there is another question similar to this, I'd appreciate a linkage.</p>