title: Merging multiple csvs the right way in panda
body: <p>I have been trying to work out how to combine several (variable amount of) csvs that all contain one same column and column data in Python. I have been looking at panda and have had only a limited success using merge, join or concat. My closest attempt was with concat (see code below). This brought together all the data but added the common field each time.</p>
  <p>So I would have for example:</p>
  <p>csv1</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Food</th>
  <th>Type</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Apple</td>
  <td>Fruit</td>
  </tr>
  <tr>
  <td>Brocolli</td>
  <td>Veg</td>
  </tr>
  <tr>
  <td>Milk</td>
  <td>Drink</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>csv2</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Food</th>
  <th>Location</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Apple</td>
  <td>UK</td>
  </tr>
  <tr>
  <td>Brocolli</td>
  <td>Spain</td>
  </tr>
  <tr>
  <td>Milk</td>
  <td>US</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Desired result csv:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Food</th>
  <th>Type</th>
  <th>Location</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Apple</td>
  <td>Fruit</td>
  <td>UK</td>
  </tr>
  <tr>
  <td>Brocolli</td>
  <td>Veg</td>
  <td>Spain</td>
  </tr>
  <tr>
  <td>Milk</td>
  <td>Drink</td>
  <td>US</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Current result (with code below):</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Food</th>
  <th>Type</th>
  <th>Food</th>
  <th>Location</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Apple</td>
  <td>Fruit</td>
  <td>Apple</td>
  <td>UK</td>
  </tr>
  <tr>
  <td>Brocolli</td>
  <td>Veg</td>
  <td>Brocolli</td>
  <td>Spain</td>
  </tr>
  <tr>
  <td>Milk</td>
  <td>Drink</td>
  <td>Milk</td>
  <td>US</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Can anyone help please?</p>
  <p>Thanks in advance</p>
  <pre><code>import glob
  import pandas as pd
  curdir = os.getcwd()
  all_files = glob.glob(os.path.join(curdir, &quot;*37604.csv&quot;))
  df_from_each_file = (pd.read_csv(csvfiles) for csvfiles in all_files)
  df_merged   = pd.concat(df_from_each_file, axis=1, ignore_index=False)
  df_merged.to_csv(&quot;merged_37604.csv&quot;, index=False)```
  
  
  </code></pre>