Advanced level · Module 5: Data Analysis with pandas · Lesson 4 of 4
Summarising and Charting Results
Aggregate data with groupby and pivot tables and present findings with clear charts.
In this lesson you will
- Summarise with groupby and pivot_table
- Create labelled bar and line charts
Key concepts
groupby/aggpivot_tablematplotlibchart labelling
The lesson
groupby() summarises data by category: df.groupby('category')['amount'].sum() gives total sales per category. pivot_table() builds two-way summaries like a spreadsheet PivotTable.
Charts make patterns visible. pandas plots with Matplotlib: choose a bar chart to compare categories and a line chart to show change over time. Always label axes and include units such as SSP.
A good summary states what the numbers show and what should be done about it. Charts support the message; they do not replace it.
Step by step
- Group sales by month and category.
- Create a bar chart and a line chart with labelled axes.
- Export the charts as PNG and the summary table to Excel.
- Write three sentences interpreting the results.
Reading a price trend with pandas
Summarise monthly prices with groupby and turn the result into a chart and a recommendation.
| Month | Market A | Market B |
|---|---|---|
| Jan | 4,200 | 4,500 |
| Feb | 4,400 | 4,600 |
| Mar | 4,900 | 5,100 |
| Apr | 5,600 | 5,800 |
| May | 6,100 | 6,500 |
| Jun | 5,800 | 6,200 |
What the data shows
The table is the output of df.groupby(['month', 'market'])['price'].mean().unstack(). Both markets rise steadily from January to May — about 45% — then ease slightly in June.
Market B is consistently 200–400 SSP more expensive, so the gap is structural rather than a one-off.
Recommendation
A school feeding programme buying monthly should agree prices or buy stock before March, and should source from Market A where transport allows. Treat the figures as illustrative: use real, dated market data for decisions.
Practice activity
Produce a one-page summary of monthly sales by category with a table and two charts, exported as PNG and Excel.
Expected result: A summary table and two correctly labelled charts.
Check your understanding
-
What three labels should every chart have?
Show answer
A title and labelled axes including units.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.