Using the rank() Method and Ranking Methods in pandas
📖 Scenario: You work in a sales team. You have a list of salespeople and their sales amounts. You want to find out their ranks based on sales to see who sold the most and who sold the least.
🎯 Goal: Build a small program that creates a sales data dictionary, sets a ranking method, applies the rank() method to find ranks of salespeople, and prints the ranked results.
📋 What You'll Learn
Create a dictionary called
sales_data with these exact entries: 'Alice': 250, 'Bob': 300, 'Charlie': 150, 'Diana': 300, 'Evan': 200Create a variable called
ranking_method and set it to the string 'min'Use pandas to create a Series from
sales_data called sales_seriesUse the
rank() method on sales_series with the method=ranking_method and ascending=False to rank sales from highest to lowestStore the result in a variable called
sales_rankPrint the
sales_rank Series💡 Why This Matters
🌍 Real World
Ranking salespeople helps managers quickly identify top performers and those who may need support.
💼 Career
Data analysts and business intelligence professionals often rank data to create reports and dashboards that inform decisions.
Progress0 / 4 steps