Skip to content
Justice Tech School

Selecting Columns

Use df["a"] for one column and df[["a", "b"]] for several.

Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
print(df["name"].tolist())
print(df[["name", "score"]].head(2))

Result

['Ada', 'Kofi', 'Amina', 'Tunde']
   name  score
0   Ada     92
1  Kofi     78

Exercise

Two columns.

df[]

Quiz Test

What does df[["a"]] return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.