How to write a python program to read multiple csv in a given folder?
Sign Up to Expert Bucket to ask questions, answer people’s questions, and connect with other people.
Login to Expert Bucket to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is an example of a Python program that reads multiple CSV files and combines them into one dataframe:
This program first imports the pandas library and os library. Then, it creates an empty list called df_list which will hold all the dataframes that are read. It then specifies the directory where the CSV files are located.
The program then uses a for loop to go through all the files in the directory and it checks if the file ends with ‘.csv’ extension, If so, it reads the file into a dataframe and adds it to the list.
Finally, it concatenates all the dataframes in the list using the
pd.concat()
function and saves it in final_df. And print the final dataframe.