Fundamentals 4 min read

How to Merge Multiple Excel Sheets with Python Pandas – A Quick Guide

This article walks through a Python automation example that reads several Excel worksheets into pandas DataFrames, renames columns, merges them on a common key, and prints the combined result, providing a practical solution for data aggregation tasks.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Merge Multiple Excel Sheets with Python Pandas – A Quick Guide

Hello everyone, I’m PiPi.

1. Introduction

Recently a member of the Python community asked about automating office tasks with Python. In this post we explore a solution that reads multiple Excel sheets, renames columns, merges the data, and outputs the combined table.

2. Implementation

The following code demonstrates the complete process:

# Read Excel sheets into DataFrames
df1 = pd.read_excel(file, sheet_name='淮海')
df2 = pd.read_excel(file, sheet_name='南京')
df3 = pd.read_excel(file, sheet_name='北京')
# Rename quantity columns
df1.rename(columns={'数量': '淮海数量'}, inplace=True)
df2.rename(columns={'数量': '南京数量'}, inplace=True)
df3.rename(columns={'数量': '北京数量'}, inplace=True)
# Merge the DataFrames on the product name
result = df1.merge(df2, on='品名', how='outer')\
            .merge(df3, on='品名', how='outer').fillna('')
print(result)

The code successfully resolves the fan’s question by automating the data aggregation.

3. Summary

This article presented a concrete Python automation example for office data processing, showing how to read Excel files, rename columns, merge them on a common field, and output the result, helping readers apply pandas for similar 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.

Automation
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.