0
0
Pandasdata~15 mins

rank() method and ranking methods in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
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': 200
Create a variable called ranking_method and set it to the string 'min'
Use pandas to create a Series from sales_data called sales_series
Use the rank() method on sales_series with the method=ranking_method and ascending=False to rank sales from highest to lowest
Store the result in a variable called sales_rank
Print 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
1
Create the sales data dictionary
Create a dictionary called sales_data with these exact entries: 'Alice': 250, 'Bob': 300, 'Charlie': 150, 'Diana': 300, 'Evan': 200
Pandas
Need a hint?

Use curly braces {} to create a dictionary with the exact names and sales numbers.

2
Set the ranking method
Create a variable called ranking_method and set it to the string 'min'
Pandas
Need a hint?

Just assign the string 'min' to the variable ranking_method.

3
Create a pandas Series and apply rank()
Import pandas as pd. Create a Series called sales_series from the dictionary sales_data. Then create a variable called sales_rank by applying the rank() method on sales_series with method=ranking_method and ascending=False.
Pandas
Need a hint?

Use pd.Series() to convert the dictionary to a Series. Then use rank() with the given method and ascending=False to rank from highest to lowest.

4
Print the ranked sales results
Write a print statement to display the sales_rank Series.
Pandas
Need a hint?

Use print(sales_rank) to show the ranks.