1.4.6 · D1Python & Scientific Computing

Foundations — Pandas DataFrames and Series basics

1,887 words9 min readBack to topic

Before you can read the parent note comfortably, you must be able to read every piece of notation it throws at you without pausing. This page collects them, defines each in plain words, ties each to a picture, and says why the topic needs it. Read top to bottom — each idea uses only the ones above it.


0. The absolute starting point: a list of values

Everything begins with the humblest object in programming: a row of values in order.

Figure — Pandas DataFrames and Series basics

Look at the figure. Each box holds a value; the small number under each box is its position (also called the integer index). The value 20 lives at position 1, not position 2, because we started counting at 0.

Why the topic needs it: A Series is built on top of a list — Pandas keeps this positional row of values and simply staples extra labels onto it. If lists feel shaky, see 1.4.02-Python-data-structures.


1. The array — a list with one fixed type

A plain Python list can mix types: [10, "cat", 3.5] is legal. Pandas doesn't want that mess inside one column.

Why the topic needs it: the parent note says a Series holds values: numpy array. The array is that inner engine. The dtype field you see printed everywhere is literally the array's declared type.


2. The label and the index — sticky name tags

Now we upgrade the array. Instead of only knowing a value's position, we give each value a name.

Figure — Pandas DataFrames and Series basics

In the figure the boxes still sit in order (position on the bottom), but now each box also wears a name tag on top (its label). The value 22000 answers to two names: "position 2" and "label 'Mar'".

Why the topic needs it: this labelled array is a Series. The parent's "index" field, and the whole .loc vs .iloc distinction later, are exactly the two-name idea drawn above.


3. The Series — labelled array with a name


4. The dictionary — the "name → value" idea, pure

Before DataFrames, meet the structure that inspired them.

Why the topic needs it: the parent builds Series "from a dictionary" and DataFrames as a "dictionary of Series". If dicts are shaky, revisit 1.4.02-Python-data-structures.


5. The DataFrame — columns sharing one index

Figure — Pandas DataFrames and Series basics

Read the figure left to right: three separate Series (name, score, grade), each with its own values but the same index ['s1','s2','s3']. Slide them together and the shared index locks the rows into a grid. That grid is the DataFrame.


6. The three ways to grab data

The parent shows df['col'], df.loc[...], df.iloc[...]. Each is just one of the two-name ideas from §2 applied to the grid.


7. Boolean values and the mask

The parent's filtering (df[df['score'] > 80]) rests on one more atom.


Prerequisite map

Ordered list at position 0 1 2

Array with one dtype

Labels and the index

Series equals values plus index plus name

Dictionary key to value

DataFrame columns sharing one index

Access trio col loc iloc

Boolean True or False

Mask filtering

Pandas DataFrames and Series

Each arrow means "you need the left idea to understand the right one". Everything funnels into the parent topic at the bottom.


Equipment checklist

Cover the answers and test yourself. If any line surprises you, reread its section above.

In [10,20,30,40], which value sits at position 1?
20 — because counting starts at 0, so position 1 is the second box.
What makes an array different from a plain list?
An array is homogeneous — every value shares one dtype, which is what enables fast vectorized operations.
What are the two ways to find a value inside a Series?
By its position (integer index 0,1,2,...) and by its label (its name tag).
Why do labels beat positions?
Labels stick to the data through sorting/filtering; positions only describe the current arrangement and can change.
What three parts make up a Series?
the values (array), the index (labels), and an optional name (title of the column).
How is a DataFrame built from Series?
Several Series placed side by side, all sharing one common index (the same row labels).
A DataFrame has shape — what does that mean?
4 rows and 3 columns (rows first).
What does df['score'] return?
The whole Series for the column named 'score'.
loc vs iloc?
loc selects by label; iloc selects by integer position (the i = integer).
Why does df['s2'] fail to fetch a row?
Plain square brackets look for a column named 's2', not a row — use .loc['s2'] for the row.
What is a boolean mask?
A Series of True/False with the same index as the data; df[mask] keeps the True rows.

Ready? Continue to the Hinglish walkthrough or push on to 1.4.07-Pandas-data-cleaningand-manipulation, then plot your data and eventually engineer features.