Fundamentals 3 min read

How to Filter Excel Data with Pandas: A Step‑by‑Step Guide

This article walks through a real‑world pandas example that filters an Excel sheet by department and ID length, shows the complete Python code, displays the resulting output, and explains how the solution resolved a reader's data‑processing question.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Filter Excel Data with Pandas: A Step‑by‑Step Guide

Hello, I'm PiPi.

1. Introduction

A few days ago a member of the Python community asked a question about using pandas to process Excel data. The original spreadsheet contains mixed Chinese and English column names, but the task is to extract rows where the "DEPT" column equals "德语系" and the "CERT_ID_F" column has a length of 10 characters.

The raw data (fields omitted for brevity) looks like this:

2. Implementation

After several attempts, the correct code was produced:

import pandas as pd

df = pd.read_excel("借阅记录.xlsx")
df1 = df[(df['DEPT'] == '德语系') & (df['CERT_ID_F'].str.len() == 10)]
print(df1)

Running the script yields the following filtered result:

This output satisfies the original request and demonstrates how to combine column value matching with string‑length filtering in pandas.

3. Conclusion

The article presented a concrete pandas solution for the Excel filtering problem, including the full code and resulting data. It illustrates a practical technique that can be adapted to similar data‑cleaning 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.

PythonTutorialExcelpandasData Filtering
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.