Generate a Formatted Report
Intermediate · Write the code · from Build a Sales Performance Dashboard with KPI Analysis
From the lesson: Step 7: Generate a Formatted Report
Data analysis is only useful if people can read it. The final step is turning raw numbers into a nicely formatted text report. Good formatting uses alignment, separators, and clear labels to make the data scannable.
Read this part of the lessonWrite a function format_report(df) that prints a complete formatted sales report. The report should include:
1. A header with the title "SALES PERFORMANCE REPORT"
2. KPI section showing total revenue, transaction count, and average order value
3. Top performers section showing the top product and top salesperson
4. Use = and - characters as separators
Match this exact format:
================================
SALES PERFORMANCE REPORT
================================
Total Revenue: $8849.86
Transactions: 5
Avg Order Value: $1769.97
--------------------------------
Top Product: Phone
Top Salesperson: Bob
================================import pandas as pd
def format_report(df):
# Your code here
pass
data = {
'product': ['Laptop', 'Phone', 'Laptop', 'Tablet', 'Phone'],
'salesperson': ['Alice', 'Bob', 'Charlie', 'Alice', 'Bob'],
'quantity': [2, 5, 1, 3, 4],
'unit_price': [999.99, 699.99, 999.99, 449.99, 699.99]
}
df = pd.DataFrame(data)
df['revenue'] = df['quantity'] * df['unit_price']
format_report(df)
More Sales Report exercises
- Create and Prepare the Sales DataFrameIntermediate
- Calculate Sales KPIsIntermediate
- Revenue by Product and RegionIntermediate
- Find Top PerformersIntermediate
- Month-over-Month GrowthIntermediate
- Create a Summary ReportIntermediate
All Python exercises · 50 practice problems · Practical Projects quiz