Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Build a Visual Metrics Dashboard | Automating Reports and Visual Insights
Python Automation for Reports and Visual Insights
Seksjon 1. Kapittel 24
single

single

bookChallenge: Build a Visual Metrics Dashboard

Sveip for å vise menyen

Oppgave

Sveip for å begynne å kode

Create a function create_dashboard(df) that accepts a DataFrame with Date, Product, and Sales columns and generates a dashboard figure with two side-by-side charts and a summary statistics box.

Compute summary statistics from the Sales column:

  • Total sales (sum), average sales (mean), maximum sales, and minimum sales

Create a figure with two subplots side by side using plt.subplots(1, 2), with the overall figure title "Sales Dashboard"

Left subplot — Line chart:

  • Group the data by Date and sum the sales, then plot as a line chart with markers
  • Set the title to "Sales Trend Over Time", x-label to "Date", y-label to "Sales"

Right subplot — Bar chart:

  • Group the data by Product and sum the sales, then plot as a bar chart
  • Set the title to "Sales by Product", x-label to "Product", y-label to "Sales"

Add a summary statistics text box at the bottom center of the figure using fig.text(). The text must follow this exact format:

Total Sales: {value:.2f}
Average Sales: {value:.2f}
Max Sales: {value:.2f}
Min Sales: {value:.2f}

Adjust the layout using plt.tight_layout() so the stats box doesn't overlap the charts.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 24
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt