5. Pandas Visualization#
This chapter introduces visualization as a management decision tool. You will learn how to choose chart types from the business question, create quick plots with pandas, keep charts honest and clear, and plot sales over time so trends and seasonal patterns stand out.
Choosing a Chart Type: The question you ask, such as a comparison, a trend, a relationship, or a distribution, decides which chart fits.
Pandas Plotting:
df.plot()builds a quick exploratory chart straight from a Series or DataFrame.Common Chart Types: Line, bar, histogram, box, and scatter plots each answer a different management question.
Plot Styling: Style sheets, color maps, and sizes make a default chart easier for an audience to read.
Honest, Clear Charts: Zero-based bars, shared scales, and takeaway titles keep a chart from misleading and help it state one finding.
Time Series: Resampling and moving averages turn noisy daily data into readable trends and seasonal patterns.
Pandas, Matplotlib, and Seaborn: Pandas is fastest for exploration, Matplotlib gives full control, and Seaborn adds statistical charts.
Chapter Video
Video credit: CrashCourse. (2018, February 21). Charts Are Like Pasta - Data Visualization Part 1: Crash Course Statistics #5. YouTube. Watch on YouTube (10:22).
This embedded video is provided for educational reference only. All rights are retained by the respective copyright holder.
Learning Objectives
By the end of this chapter, you will be able to:
Choose chart types that match categorical, quantitative, relationship, and time-based questions.
Create quick exploratory plots from pandas Series and DataFrame objects.
Compare line, bar, histogram, box, and scatter plots for common management analyses.
Adjust labels, scales, legends, and styling so a chart is honest and states a clear finding.
Resample and smooth date-indexed data to show trends and seasonal patterns.
Explain when pandas, Matplotlib, and Seaborn are useful in a visualization workflow.
Chapter Flow
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Data visualization |
Using charts and graphs to reveal patterns in data. |
2 |
Audience |
The people who need to understand or act on a chart. |
3 |
Chart type |
A visual form such as a bar chart, line chart, or scatter plot. |
4 |
Categorical variable |
A variable whose values are labels or groups. |
5 |
Quantitative variable |
A variable measured with numeric values. |
6 |
Frequency |
The count of observations in a category or interval. |
7 |
Relative frequency |
A frequency expressed as a proportion or percentage. |
8 |
Bar chart |
A chart that compares values across categories. |
9 |
Line chart |
A chart that shows change across an ordered sequence. |
10 |
Scatter plot |
A chart that displays paired numeric values as points. |
11 |
Histogram |
A chart that shows the distribution of one numeric variable. |
12 |
Box plot |
A compact summary of median, quartiles, and possible outliers. |
13 |
Axis |
A reference line that provides the scale for values. |
14 |
Legend |
A guide that maps colors or symbols to groups. |
15 |
Label |
Text that names axes, categories, or marks. |
16 |
Scale |
The mapping between data values and visual positions. |
17 |
Outlier |
An observation that sits far from the main pattern. |
18 |
Pandas plotting |
The DataFrame and Series plotting interface built on Matplotlib. |
19 |
Matplotlib |
A flexible Python library for building and customizing plots. |
20 |
Seaborn |
A statistical visualization library built on Matplotlib. |
21 |
Encoding |
The use of position, color, size, or shape to represent data. |
22 |
Comparison question |
A question about how categories rank against each other; a bar chart is the usual first choice. |
23 |
Trend question |
A question about how a number changes over time; a line chart is the usual first choice. |
24 |
Distribution question |
A question about which values are typical and how spread out they are; try a histogram or box plot. |
25 |
Relationship question |
A question about whether two numbers move together; try a scatter plot. |
26 |
Part-to-whole question |
A question about how a total splits into pieces; try a stacked bar chart. |
27 |
Truncated axis |
A value axis that starts above zero, which exaggerates the differences between bars. |
28 |
Zero baseline |
The rule that bar charts start at zero because bar length encodes the value. |
29 |
Takeaway title |
A chart title that states the finding rather than only the topic. |
30 |
Reference line |
A line marking a target or average so readers can compare values against it. |
31 |
Sequential colormap |
Colors that run from light to dark for ordered, low-to-high values. |
32 |
Diverging colormap |
Colors that run in two directions from a meaningful middle such as zero or a target. |
33 |
Categorical colormap |
Distinct colors for groups that have no order. |
34 |
Time series |
A sequence of values recorded at regular points in time, such as daily revenue. |
35 |
Datetime index |
An index made of dates; it puts dates on the x-axis and enables resampling and date slicing. |
36 |
Resampling |
Changing the time unit of a time series, for example from days to months, with |
37 |
Moving average |
The average over a sliding window of recent periods; it smooths noise but can hide short patterns. |
38 |
Trend |
The long-run direction of a time series: up, down, or flat. |
39 |
Seasonality |
A pattern that repeats on a fixed calendar cycle, such as a December peak every year. |
40 |
Small multiples |
A set of small charts, one per series, drawn on shared axes for side-by-side comparison. |