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

pago
1 min readMar 9, 2022
  • In a min, you can data manipulation as Excel & Python Expert

Step 1

  • Installation of free python tools for MacBook/Windows using pycharm program with anaconda
    → a link for installation guide

Step 2

  • Installation python plug-ins for Excel
    → a link for installation guide
  • 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

  • Writing a source Code (Sample) → a video link for installtion guide (tbd)

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)

--

--

pago

Proficient in authoring tools and has a keen eye for detail. Passionate about technical writing and always seeking to improve.