Editor

Find Top Performers

Intermediate · Write the code · from Build a Sales Performance Dashboard with KPI Analysis

From the lesson: Step 4: Find Top Performers

Sales managers love rankings. Who's the top salesperson? What's the single biggest sale? Let's write code that answers both.

Read this part of the lesson

Write a function find_top_performers(df) that prints:

1. The top salesperson by total revenue (print: Top salesperson: NAME ($REVENUE))

2. The top product by total units sold (print: Top product: NAME (UNITS units))

3. The largest single sale by revenue (print: Largest sale: $REVENUE by NAME)

Format all dollar amounts with 2 decimal places.

import pandas as pd
def find_top_performers(df):
# Your code here
pass
data = {
'salesperson': ['Alice', 'Bob', 'Alice', 'Charlie', 'Bob'],
'product': ['Laptop', 'Phone', 'Phone', 'Laptop', 'Tablet'],
'quantity': [2, 5, 3, 1, 4],
'unit_price': [999.99, 699.99, 699.99, 999.99, 449.99]
}
df = pd.DataFrame(data)
df['revenue'] = df['quantity'] * df['unit_price']
find_top_performers(df)

More Sales Report exercises

All Python exercises · 50 practice problems · Practical Projects quiz