How to merge a few excel files into one (Python+Excel method #1, w/openpyxl)

Step 1

Step 2

  • Step by Step

Step 2–1. Move to terminal in PyCharm

Step 2- 2. Install plug-in using a comment : pip install package-name (openpyxl-xxxx, pandas)

Example : pip install openpyxl

Step 3

Step 3–1. Creation three excel files to merge as one file, then run python code to merge those (tmp1.xlsx, tmp2.xlsx, tmp3.xlsx → merged_one.xlsx)

→ a sample code

import pandas as pd
from pathlib import Path
input_folder = '/Users/tippang/PycharmProjects/pythonProject2/tmp'
raw_data_dirpath = Path(input_folder)
excel_files = raw_data_dirpath.glob('tst*')
merge_df = pd.DataFrame()for excel_file in excel_files:
df = pd.read_excel(excel_file)
merge_df = merge_df.append(df, ignore_index=True)
merged_excel_file = input_folder + 'integrated_file.xlsx'
merge_df.to_excel(merged_excel_file, sheet_name='1Q_Data', index=False)
print("crated file", merged_excel_file)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store