Stop 03 · Data Manipulation & VisualizationTopics · 2/10

Pandas DataFrames & Series

Part of the AI Engineer Roadmap

In short

Almost every dataset you touch will pass through pandas. It's like Excel you can program: load a file, filter rows, add columns and summarise, all in a few readable lines.

Pandas' tabular data structures for loading, exploring and transforming datasets — the tool you'll use in almost every data task before modeling.

The purple blob points at a classroom board with coloured cards pinned in rows and columns.

Think of it like this

The class attendance register

The register has one row per student and one column per day, with roll numbers down the side. A DataFrame is that whole register. One column, like Monday's attendance, is a Series. The roll numbers are the index, the labels you look rows up by.

Watch it happen

Inside a DataFrame

df (DataFrame)
index 0, 1, 2…
name: Series
city: Series
marks: Series

1/4df is the whole table. df.shape tells you rows and columns, like (120, 3).

The big ideas

What you need to know

Load in one line

pd.read_csv, read_excel, read_json and read_sql cover most formats. Always check df.head() and df.info() right after.

Filter with conditions

df[df['marks'] > 80] keeps matching rows. Combine conditions with & and |, each wrapped in brackets.

loc for labels, iloc for positions

df.loc[5, 'city'] uses the index label and column name. df.iloc[0, 1] uses plain positions.

New columns are easy

df['grade'] = df['marks'] // 10 creates a column for every row at once, no loop needed.

See it in code

Walk through the code

python
1import pandas as pd2 3df = pd.DataFrame({4    "name": ["Asha", "Bilal", "Charu", "Dev"],5    "city": ["Pune", "Delhi", "Pune", "Chennai"],6    "marks": [91, 67, 78, 85],7})8 9df.info()                              # columns, types, missing counts10print(df["marks"].mean())              # 80.2511print(df[df["marks"] > 80])            # Asha and Dev12print(df.loc[df["city"] == "Pune", "name"].tolist())   # ['Asha', 'Charu']13 14df["passed"] = df["marks"] >= 7015print(df.sort_values("marks", ascending=False).head(2))

1/4Build a small DataFrame from a dict of columns.

Most daily pandas work is these moves: inspect, select, filter, add a column, sort. In real work df comes from read_csv instead of a dict.

Save yourself the pain

Common mistakes

Oops

Writing df[df['a'] > 1 and df['b'] < 5].

Do this instead

Use & with brackets: df[(df['a'] > 1) & (df['b'] < 5)]. Python's and doesn't work on whole columns.

Oops

Changing a filtered slice and getting a SettingWithCopyWarning.

Do this instead

Use df.loc[condition, 'col'] = value, or call .copy() on the slice before editing it.

Your mission

Explore a real table

~20 min

Quick check

What type is df['marks'] when df is a DataFrame?

Go deeper

  1. 1Load a real CSV dataset and practice filtering, selecting and sorting rows/columns.
  2. 2Learn `.loc` vs `.iloc` and when to use each.
  3. 3Practice chaining pandas operations into clean, readable pipelines.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge