HOWTO · Python

How to Import Multiple CSV Files Into Pandas and Concatenate Into One DataFrame

This tutorial demonstrates how to import multiple CSV files using Pandas and concatenate them into single DataFrame.

On this page

Load each matching CSV file with pandas.read_csv(), then combine the resulting DataFrames with pd.concat(). The workflow is to find the files in one folder, read them in a predictable order, and create one DataFrame with a fresh row index. Install the pandas package first if it is not already available in your Python environment.

Read a single CSV file with pandas

The pandas package provides read_csv() for loading a CSV file into a DataFrame. For one file, call df = pd.read_csv("sales.csv") and replace the filename with the path to your data. The function reads the first row as column names by default, so use the resulting DataFrame’s column labels to check that the file was parsed as intended. This same operation is used for every path in the multi-file workflow.

Find CSV files with glob and build paths

Python’s standard-library glob module finds paths that match a pattern, so there is no separate package to install. glob.glob() returns matching paths as a list. Combine a folder and a filename pattern with os.path.join() so Python builds a path with the appropriate separator for the platform:

pattern = os.path.join(folder, "*.csv")

The *.csv pattern selects CSV files directly inside the chosen folder. To include nested folders, use a recursive glob pattern and set recursive=True in the glob.glob() call. On Windows, a raw string such as r"C:\data\sales" keeps backslashes from being interpreted as escape sequences; os.path.join() can add the filename pattern to that folder path.

Read multiple CSV files and concatenate the DataFrames

Collect the matching paths, call read_csv() once for each path, then pass the resulting DataFrames to pd.concat(..., ignore_index=True). This complete example creates two small CSV files in a temporary folder, so it can run as written without companion files. For your own data, replace the sample-file setup with a folder path and keep the path discovery, reading, and concatenation steps. If the pattern finds no files, the example prints a message and skips reading and concatenation. The final print displays the combined rows when files match.

import glob
import os
import tempfile
from pathlib import Path

import pandas as pd

with tempfile.TemporaryDirectory() as temp_dir:
    folder = Path(temp_dir)
    (folder / "jan.csv").write_text("month,sales\nJan,10\n", encoding="utf-8")
    (folder / "feb.csv").write_text("month,sales\nFeb,12\n", encoding="utf-8")

    pattern = os.path.join(str(folder), "*.csv")
    csv_paths = sorted(glob.glob(pattern))
    if not csv_paths:
        print("No CSV files found.")
    else:
        dataframes = [pd.read_csv(csv_path) for csv_path in csv_paths]
        combined = pd.concat(dataframes, ignore_index=True)
        print(combined.to_string(index=False))
month  sales
  Feb     12
  Jan     10

Sorting the paths makes the file order predictable: rows follow that order, followed by their original order within each file. ignore_index=True assigns a new sequential index to all combined rows. When files have different column names, pandas aligns values by column label and fills missing values with NaN; use consistent column names when each row should represent the same fields. Check that the match list contains files before concatenating, since pd.concat() needs at least one DataFrame. If no files match, adjust the folder or pattern before running the read-and-combine step.