Fundamentals 5 min read

How to Merge Multiple Excel Performance Sheets with Python Pandas

Learn how to automate the consolidation of multiple employee performance Excel files into a single spreadsheet using Python's pandas library, with step‑by‑step code, common pitfalls, and tips for handling file paths and engine settings.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Merge Multiple Excel Performance Sheets with Python Pandas

Hello, I'm PiPi. This article addresses a Python automation task: merging multiple employee performance Excel files into one.

1. Problem Description

A user has a folder containing several Excel files, each with two columns: date and performance score. The goal is to combine them into a single Excel workbook.

Excel file example
Excel file example

2. Implementation

The solution uses pandas to read each file, concatenate the data frames, and export the combined result.

import pandas as pd
import os

file_names = os.listdir("C:/Users/pdcfighting/Desktop/绩效")  # Get all file names in the target folder
df1 = pd.DataFrame({"日期": [], "绩效得分": []})
for file in file_names:  # Iterate over each file
    df2 = pd.read_excel("C:/Users/pdcfighting/Desktop/绩效/" + file, engine='openpyxl')
    df3 = pd.concat([df1, df2])  # Vertical concatenation
    df1 = df3
    print(f"{file}已经合并!")

print(df1)
df1.to_excel("合并表格.xlsx", engine='openpyxl')

Running the script produces the expected merged spreadsheet.

Merged result
Merged result

3. Common Issues

If you encounter an error about missing openpyxl, ensure the engine is installed. Also, avoid placing the Python script in the same directory as the Excel files, otherwise the script may try to read itself and cause errors.

Error screenshot
Error screenshot

4. Conclusion

This guide demonstrates how to automate Excel merging with Python, providing a practical solution for handling repetitive data consolidation tasks.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

pandas
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.