ASAmol Shukla
Projects
Learning Hub
Prompts
Skills
Contact
Resume
Course Outline
Syllabus Overview

Data Science: NumPy, pandas, Matplotlib, seaborn & Plotly

Courses/Data Science: NumPy, pandas, Matplotlib, seaborn & Plotly/seaborn foundations: distributions and category comparisons

Data Science

seaborn foundations: distributions and category comparisons

Use tidy DataFrames with histplot, scatterplot and boxplot while distinguishing transactions from aggregates.

90 mins12 mins read

What you will learn

Use tidy DataFrames with histplot, scatterplot and boxplot while distinguishing transactions from aggregates.

Before you start

You need basic variables, lists and function calls, not advanced Python algorithms. If these are new, visit Python foundations first.

  1. Create a local environment: python -m venv .venv. Activate it for your OS and install python -m pip install jupyterlab numpy pandas matplotlib seaborn plotly.
  2. Download the 12-row sales CSV into your notebook folder. Keep its filename unchanged.
  3. Start Jupyter with jupyter lab. Run the setup below in a fresh notebook before every workshop.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
raw = pd.read_csv('data-science-sales.csv', parse_dates=['date'])
df = raw.copy()
df['revenue'] = df['units'] * df['unit_price']
net = df.loc[df['returned'].eq(0)].copy()

Data dictionary: each row is one order for one product; units is a positive count; unit_price is INR per unit; returned is 0 or 1. Revenue is units × unit_price. For this workshop, net sales exclude the entire returned order (not partial returns). The CSV has 12 rows, 4950 gross revenue, 4450 net revenue and 35 net units. This small fictional sample teaches technique; it does not justify population or causal claims.

Save your notebook and written interpretation. There is no browser code judge and no automatic grading of visual design.

Official seaborn documentation

Learn the idea

seaborn builds statistical plots on Matplotlib and works with column names in a tidy DataFrame. histplot shows the distribution of observations; boxplot summarises median and spread. A barplot defaults to a statistical estimator rather than summing raw transactions: pre-aggregate totals when reporting revenue and disable error bars for that deterministic summary. Twelve rows are not enough to make strong population claims; show counts and avoid treating a smoothed curve as certainty.

Follow a worked example

fig,ax=plt.subplots(figsize=(6,4))
sns.histplot(data=net,x='revenue',bins=5,ax=ax)
ax.set(xlabel='Order revenue (INR)',ylabel='Order count',title='Distribution of 11 non-returned orders')
fig.tight_layout(); plt.show()

Expected result

A five-bin histogram of 11 net orders. This is order revenue, not regional total revenue.

Skill-development workshop

These are practical assignments, not MCQs or code-judge puzzles. Work in your own notebook or MySQL client. Complete the levels in order; if a task feels difficult, follow the hint and compare with the reference only after making an attempt. Keep your result and a short explanation of what it means.

Easy: Plot the distribution of units per order.

Success criteria: 11 observations, discrete count axis, clear title.

Need a starting point? Show the hint

Use histplot(discrete=True) on units.

Reference solution — open after trying
fig,ax=plt.subplots(); sns.histplot(data=net,x='units',discrete=True,ax=ax); ax.set(title='Units in non-returned orders',ylabel='Orders'); plt.show()

Medium: Compare order-revenue distributions by region.

Success criteria: Three boxes with counts North 4, South 4, West 3 noted; no claim of statistical significance.

Need a starting point? Show the hint

Use boxplot and print group sizes beside the chart.

Reference solution — open after trying
fig,ax=plt.subplots(); sns.boxplot(data=net,x='region',y='revenue',order=['North','South','West'],ax=ax); ax.set_ylabel('Order revenue (INR)'); plt.show()
print(net.groupby('region').size())

Hard: Plot regional totals without accidentally showing mean order value.

Success criteria: 1350,1700,1400, not regional means; no misleading error bars.

Need a starting point? Show the hint

Pre-aggregate with groupby, then use errorbar=None.

Reference solution — open after trying
summary=net.groupby('region',as_index=False)['revenue'].sum()
fig,ax=plt.subplots(); sns.barplot(data=summary,x='region',y='revenue',errorbar=None,ax=ax); ax.set_ylabel('Net revenue (INR)'); plt.show()

Professional: Explain estimator choice in a stakeholder comparison.

Success criteria: A table shows total, mean and count per region; report explains that they answer different questions.

Need a starting point? Show the hint

Named agg gives all three metrics without changing input data.

Reference solution — open after trying
summary=net.groupby('region').agg(total=('revenue','sum'),mean_order=('revenue','mean'),orders=('order_id','count'))
print(summary)
print('Total measures contribution; mean measures typical order value; count measures activity. Small groups limit inference.')

Reflection and submission

Save your queries/notebook and outputs. Write three sentences: what you changed, how you checked it, and one limitation. A correct chart or query without a clear interpretation is not a completed professional assignment.

python · worked example
fig,ax=plt.subplots(figsize=(6,4))
sns.histplot(data=net,x='revenue',bins=5,ax=ax)
ax.set(xlabel='Order revenue (INR)',ylabel='Order count',title='Distribution of 11 non-returned orders')
fig.tight_layout(); plt.show()
Read-only sample

Lesson Code (python)

fig,ax=plt.subplots(figsize=(6,4))
sns.histplot(data=net,x='revenue',bins=5,ax=ax)
ax.set(xlabel='Order revenue (INR)',ylabel='Order count',title='Distribution of 11 non-returned orders')
fig.tight_layout(); plt.show()

Console Output

A five-bin histogram of 11 net orders. This is order revenue, not regional total revenue.

Up next · Continue learning

faceting, correlation and honest EDA

Separate groups with facets, inspect correlations and write cautious exploratory conclusions.

12 mins read90 mins
Start next lesson
Previous: Matplotlib professional layouts, annotations and exportNext: faceting, correlation and honest EDA
Made withbyAmol Shukla·amolshukla.online
ASAmol Shukla

AI Developer, Trainer & Agentic AI Expert building practical learning systems and real-world AI applications.

Explore

  • Projects
  • Learning Hub
  • Prompts
  • Skills
  • Contact
  • Experience
  • Blogs

Connect

  • Resume
  • Contact
© 2026 Amol Shukla·Created withbyamolshukla.online
Back to top