> ## Content Index
> Fetch the complete content index at: https://datascientyst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How To Read Multiple CSV Files into Pandas DataFrame
- URL: https://datascientyst.com/how-to-read-multiple-csv-files-into-pandas-dataframe/
- Published: 2023-08-27T09:16:10.000Z
- Updated: 2023-08-27T09:16:10.000Z
- Author: John D K
- Tags: read_csv()

To read multiple CSV file into single Pandas DataFrame we can use the following syntax:

**(1) Pandas read multiple CSV files**

```python
path = r'/home/user/Downloads'
all_files = glob.glob(path + "/*.csv")

lst = []

for filename in all_files:
	df = pd.read_csv(filename, index_col=None, header=0)
	lst.append(df)

merged_df = pd.concat(lst, axis=0, ignore_index=True)

```

**(2) Read multiple CSV files - Dask**

```python
import dask.dataframe as dd
df = dd.read_csv("~/Downloads/test*.csv")

```

## Pandas Example

Suppose that we would like to read all CSV files:

- located in folder - `/home/user/Downloads`
- by pattern - `/test_*.csv` \- starting with `test_` and ending on `.csv`

We can use the following code:

```python
import glob
import pandas as pd

path = r'/home/user/Downloads'
pattern = "/test_*.csv"
all_files = glob.glob(path + pattern)

lst = []

for filename in all_files:
	df = pd.read_csv(filename, index_col=None, header=0)
	lst.append(df)

merged_df = pd.concat(lst, axis=0, ignore_index=True)

```

Let's say that we have the following files in this folder:

- other.csv
- test\_1.csv
- test\_2.csv

In the final DataFrame - merged\_df we will have content only from files - test\_1.csv and test\_2.csv:

![](https://datascientyst.com/content/images/2023/08/read-multiple-csv-files-into-pandas-dataframe.webp)

## Read multiple CSV files with Dask

As an alternative solution we can use the dask module to read multiple CSV files. To install Dask you can visit: [dask](https://pypi.org/project/dask/?ref=datascientyst.com) or use: `pip install dask`.

To read multiple files from a folder with pattern we can use:

```python
import dask.dataframe as dd
df = dd.read_csv("~/Downloads/test*.csv")

```

## Resources

For more advanced examples on reading multiple CSV or JSON files with Pandas you can check:

- [How to Merge multiple CSV Files in Linux Mint](https://softhints.com/merge-multiple-csv-files-linux-mint/?ref=datascientyst.com)
- [How to Merge Multiple JSON Files with Python](https://softhints.com/merge-multiple-json-files-pandas-dataframe/?ref=datascientyst.com)
- [Convert Pandas to Dask DataFrame ( Dask to Pandas )](https://datascientyst.com/convert-pandas-to-dask-dataframe-dask-to-pandas/)