How to combine multiple CSV files into one DataFrame

If your all .csv files in the same directory, you can use the following methods:

df = pd.concat(map(pd.read_csv, all_files))

Full Source:

import pandas as pd import numpy as np import glob import os path = r'D:\csv' all_files = glob.glob(path + "/*.csv") df = pd.concat(map(pd.read_csv, all_files))

Method 2: Reading Multiple CSVs Into Pandas


Reading Multiple CSVs Into Pandas
import pandas as pd import numpy as np import glob path = r'D:\csv' all_files = glob.glob(path + "/*.csv") df_files = (pd.read_csv(f) for f in all_files) df = pd.concat(df_files, ignore_index=True)
Glob: The python module glob provides Unix style pathname pattern expansion. So, using glob.glob('*.csv') will give you all the .csv files in a folder as a list.