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/pandas foundations: loading, selecting and validating data

Data Science

pandas foundations: loading, selecting and validating data

Read a CSV, inspect types, select rows and repair a controlled dirty copy without silently changing the original.

90 mins12 mins read

What you will learn

Read a CSV, inspect types, select rows and repair a controlled dirty copy without silently changing the original.

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 pandas documentation

Learn the idea

A DataFrame has labelled columns and an index. Use head(), info() and shape before analysis. loc selects labels and masks; iloc selects positions. Missing values are not zeros: choose a repair only when the business rule permits it. Use a new DataFrame for cleaning experiments. Drop duplicates on the business key, not every repeated value. Avoid chained assignment; use .loc or .assign and retain a raw copy.

Follow a worked example

print(raw.shape)
print(raw['order_id'].is_unique)
print(raw.isna().sum().sum())

Expected result

(12, 7), True, 0. The source CSV is clean; dirty-data exercises deliberately create a copy.

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: Select order_id and product for the first three rows.

Success criteria: Three rows: Notebook, Pen, Lamp; two columns.

Need a starting point? Show the hint

Column-list selection followed by head(3).

Reference solution — open after trying
print(raw[['order_id','product']].head(3))

Medium: Filter South orders with at least two units.

Success criteria: Order ids [2,5,11].

Need a starting point? Show the hint

Combine masks with & and parenthesise each comparison.

Reference solution — open after trying
result=raw.loc[(raw['region']=='South') & (raw['units']>=2)]
assert result['order_id'].tolist()==[2,5,11]

Hard: Repair a duplicated row and a missing region in a dirty copy.

Success criteria: 12 unique orders, no missing region; the deliberately missing value is labelled Unknown, not guessed.

Need a starting point? Show the hint

Concatenate the first row; blank row 0's region; fill then deduplicate on order_id.

Reference solution — open after trying
dirty=pd.concat([raw,raw.iloc[[0]]],ignore_index=True)
dirty.loc[0,'region']=None
clean=dirty.assign(region=dirty['region'].fillna('Unknown')).drop_duplicates('order_id',keep='first')
assert len(clean)==12 and clean['order_id'].is_unique
assert clean['region'].isna().sum()==0

Professional: Write a data-quality gate before revenue reporting.

Success criteria: Reject duplicate ids, nonpositive units/prices, invalid returns, missing dates. All checks pass on raw.

Need a starting point? Show the hint

Assert the input contract rather than deleting problematic rows silently.

Reference solution — open after trying
assert raw['order_id'].is_unique
assert raw[['order_id','date','region','product','units','unit_price','returned']].notna().all().all()
assert raw['units'].gt(0).all() and raw['unit_price'].gt(0).all()
assert raw['returned'].isin([0,1]).all()
assert pd.api.types.is_datetime64_any_dtype(raw['date'])

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
print(raw.shape)
print(raw['order_id'].is_unique)
print(raw.isna().sum().sum())
Read-only sample

Lesson Code (python)

print(raw.shape)
print(raw['order_id'].is_unique)
print(raw.isna().sum().sum())

Console Output

(12, 7), True, 0. The source CSV is clean; dirty-data exercises deliberately create a copy.

Up next · Continue learning

groupby, joins, pivots and time series

Turn row-level sales into reconciled regional and monthly reports, validating joins before they duplicate revenue.

12 mins read90 mins
Start next lesson
Previous: broadcasting, statistics and safe divisionNext: groupby, joins, pivots and time series
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