Merge Multiple Employee Excel Files into One with Python – Step‑by‑Step Guide
Learn how to automate the consolidation of numerous employee performance Excel files using Python and pandas, with a clear code example that reads each workbook, concatenates the data, and outputs a single merged spreadsheet, while also offering tips for handling file formats and avoiding common pitfalls.
Introduction
In a recent Python community query, a user asked how to automatically combine multiple Excel files containing employee performance data (date and score) into a single spreadsheet.
Solution
The provided Python script uses pandas to read each Excel file in a specified folder, concatenate the data vertically, and save the combined result.
import pandas as pd
import os
file_names = os.listdir("C:/Users/pdcfi/Desktop/绩效") # get all file names
df1 = pd.DataFrame({"日期": [], "绩效得分": []})
for file in file_names:
if file.endswith(".xlsx") or file.endswith(".xls"):
df2 = pd.read_excel("C:/Users/pdcfi/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, as shown in the screenshots.
The result confirms that all employee performance tables have been successfully combined without reading errors.
Conclusion
This article demonstrates a practical Python automation solution for merging Excel files, providing the full code and explaining each step, which helps users efficiently handle similar data‑processing tasks.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
