Convert Excel Scores to Grade Levels Using Python Pandas
This article explains how to transform numeric scores in multiple Excel sheets into categorical grades (Excellent, Good, Average, Poor) with Python, preserving any existing Chinese text, and provides a concise, reusable solution illustrated with screenshots.
1. Introduction
Hello, I am PiPi. Recently, a request was shared in a Python community to convert numeric scores in three Excel sheets into four grade categories: 100 points as "Excellent", 80‑99 as "Good", 60‑79 as "Average", and below 60 as "Poor". Any existing Chinese text in the cells should be retained (e.g., "Chinese 100" becomes "Chinese Excellent").
2. Implementation
The solution builds on a previous method that used a clean and efficient code snippet to address similar data‑processing tasks. Below are the key steps and screenshots demonstrating the approach:
Another method, provided by a contributor, works uniformly across all three sheets, avoiding the need for separate handling of each sheet.
The technique uses pandas' cut function (or an equivalent custom mapping) to map numeric ranges to the desired grade labels while preserving any non‑numeric characters.
3. Summary
This article presented a practical Python automation solution for converting scores to grade levels in Excel files, offering clear code and visual guidance to help readers apply the method to similar data‑analysis problems.
Additional tips: when sharing large datasets, anonymize sensitive data, provide a small demo file, and include error screenshots. For longer scripts (over 50 lines), attach a .py file.
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.
