Merging All CSV files in a folder with Pandas

Merging All CSV files in a folder with Pandas
Merging All CSV files in a folder with Pandas

So I will show you some ways to merge CSV files located in a folder with the pandas library. Inspiration was found on Stackoverflow.

So if you haven’t installed pandas yet, that would be the first thing to do.

Simply type the following:

pip install pandas

Or, if you are running conda, you can type:

conda install pandas

When that is done, the way you want to structure it is to read several CSV files from a directory into pandas; that way, you can concatenate them into one big DataFrame. The python code would look like

import glob, os
import pandas as pd   
df = pd.concat(map(pd.read_csv, glob.glob(os.path.join('', "my_files*.csv"))))

This is good if you don’t need any read_csv arguments.