How to use the glob package In Python Pandas
The glob module in python is used to retrieve files or pathnames matching a specified pattern.
This program is similar to the above program but the only difference is instead of keeping track of file names using a list we use the glob package to retrieve files matching a specified pattern.
Example: Reading multiple CSV files using Pandas and glob.
Python3
# importing packages import pandas as pd import glob folder_path = 'Path_of_file/csv_files' file_list = glob.glob(folder_path + "/*.csv" ) main_dataframe = pd.DataFrame(pd.read_csv(file_list[ 0 ])) for i in range ( 1 , len (file_list)): data = pd.read_csv(file_list[i]) df = pd.DataFrame(data) main_dataframe = pd.concat([main_dataframe,df],axis = 1 ) print (main_dataframe) |
Output:
How to read multiple data files into Pandas?
In this article, we are going to see how to read multiple data files into pandas, data files are of multiple types, here are a few ways to read multiple files by using the pandas package in python.
The demonstrative files can be download from here