Pandas is the spreadsheet of Python — the tool analysts and data scientists live in. It's built on NumPy and adds labelled rows and columns, so you work with named fields instead of raw array positions. If you know Excel and the NumPy course, pandas will feel familiar fast. This is where real data cleaning and analysis happens.
Why pandas?
Real data arrives messy: CSVs with missing values, mixed types, inconsistent labels. Pandas gives you fast, expressive tools to load, clean, reshape, group and summarise that data — the 80% of any data project that isn't modelling. The convention is import pandas as pd.
Series & DataFrame
A Series is a labelled 1-D column. A DataFrame is a 2-D table — a dict of Series sharing one index. The DataFrame is what you'll use 95% of the time:
import pandas as pd# A Series — one labelled columns = pd.Series([6.5, 8.0, 7.25], name="package")# A DataFrame — a whole tabledf = pd.DataFrame({"name": ["Aanya", "Rohan", "Priya"],"programme": ["Data", "Full Stack", "Data"],"package": [6.5, 8.0, 7.25],})df
Every DataFrame has an index (the row labels, 0,1,2… by default) and named columns. Almost every operation returns a new DataFrame, leaving the original untouched.
Loading data
You'll rarely type data by hand — you'll read it from a file or database:
df = pd.read_csv("students.csv")df = pd.read_excel("report.xlsx", sheet_name="Sheet1")df = pd.read_json("data.json")# Common read_csv optionsdf = pd.read_csv("students.csv",parse_dates=["enrolled"], # parse a date columnna_values=["N/A", "-"]) # treat these as missing# Save back outdf.to_csv("clean.csv", index=False)
Inspecting a dataset
The first five commands you run on any new DataFrame — before anything else:
| Command | Tells you |
|---|---|
df.head() | First 5 rows (df.tail() for the last) |
df.shape | (rows, columns) |
df.info() | Columns, non-null counts, dtypes |
df.describe() | Summary stats for numeric columns |
df["col"].value_counts() | Frequency of each value in a column |
df.head()df.info()df.describe()df["programme"].value_counts()
Practice
Load any CSV you have (or make a small one). Run head, shape, info and describe, and value_counts() on a categorical column. Note which columns have missing values or an unexpected dtype.
Key takeaways
- 01Pandas is Python's data-analysis library — labelled tables built on NumPy. Import it as pd.
- 02A Series is a labelled column; a DataFrame is a labelled 2-D table with an index and named columns.
- 03Load data with read_csv / read_excel / read_json; write back with to_csv(index=False).
- 04Inspect every new dataset with head, shape, info, describe and value_counts.
- 05df.info() first — it exposes wrong dtypes and missing values before they bite.
