Skip to main content

Merge Multiple CSV Files in a folder to Excel using Python with Pandas

Step 1
You have install Pandas before using it. Eun the following command on the cmd
python pip install pandas
Step 2
In case if you get any error regarding missing modules, run the following command
pip install openpyxl xlsxwriter xlrd
Step 3
Create a new file as "csvs_to_excel.py" and paste the following code there.
import os
import glob
import pandas as pd
extension = 'csv'
all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
combined_csv = pd.concat([pd.read_csv(f) for f in all_filenames ])
combined_csv.to_excel('combined.xlsx', index=False)

Comments