How to Merge multiple CSV Files into a single Pandas dataframe ? (original) (raw)

Last Updated : 23 Jul, 2025

While working with CSV files during data analysis, we often have to deal with large datasets. Sometimes, it might be possible that a single CSV file doesn't consist of all the data that you need. In such cases, there's a need to merge these files into a single data frame. Luckily, the Pandas library provides us with various methods such as merge, concat, and join to make this possible. Through the examples given below, we will learn how to combine CSV files using Pandas.

File Used:

First CSV -

Second CSV -

Third CSV -

Method 1: Merging by Names

Let us first understand each method used in the program given above:

Approach:

Example:

Python3 `

importing pandas

import pandas as pd

merging two csv files

df = pd.concat( map(pd.read_csv, ['mydata.csv', 'mydata1.csv']), ignore_index=True) print(df)

`

Output:

Method 2: Merging All

Approach:

We can simply write these three lines of code as:

df = pd.concat(map(pd.read_csv, glob.glob(os.path.join("/home", "mydata*.csv"))), ignore_index= True)

Example:

Python3 `

importing libraries

import pandas as pd import glob import os

merging the files

joined_files = os.path.join("/home", "mydata*.csv")

A list of all joined files is returned

joined_list = glob.glob(joined_files)

Finally, the files are joined

df = pd.concat(map(pd.read_csv, joined_list), ignore_index=True) print(df)

`

Output: