Lesson 3: Pandas DataFrames – The Heart of Data Tables

1. What is a DataFrame?

A DataFrame is a 2D table with rows & columns — like Excel or SQL table.

Each column is a Series → same power + table structure.

import pandas as pd

data = {
    "name": ["Alice", "Bob", "Charlie"],
    "age": [25, 30, 35],
    "city": ["NY", "LA", "SF"]
}
df = pd.DataFrame(data)
print(df)

Rows indexed 0,1,2; columns: name, age, city.

Exercise 1

After creating df above, df["age"] returns a
df.loc[1, "city"] returns

2. Accessing & Modifying DataFrames

axis=0 = rows, axis=1 = columns.

Exercise 2

How to get the second row as a Series?

Exercise 3

Which are correct ways to add a new column?
← Previous Lesson (2) Next Lesson (4) →