LambdaLabTM
Informatics Practices · Class 12 · Python Pandas · DataFrame
PandasDataFrame⏱️ 6 min read

Selecting Columns

The most everyday thing you do with a DataFrame is pull out a column. Each column comes back as a Series — the same 1-D structure you already know.

1One column at a time

Put the column name in square brackets. You can also use dot notation — but only when the name is a single word with no spaces.

one_column.py
Watch Out
Dot notation fails on multi-word names: df.IP Marks is a syntax error. When in doubt, use df['IP Marks'].

2Several columns at once

Pass a list of column names inside the square brackets. The columns come back in the order you list them — and the result is a DataFrame, not a Series.

many_columns.py

3Going one step further: a single value

A selected column is a Series, and a Series lets you ask for one label. So add a second pair of brackets — the row label — and you land on a single cell. Read it as column first, then row.

one_value.py
Note
This is the quick shortcut. Later, in the loc/iloc lesson, you'll meet df.at['ID 1', 'Name'] — the proper way to reach one cell, and it reads row first, then column.
Key Takeaway
df['col'] → one column as a Series. df[['a', 'b']] → several columns as a DataFrame (note the double brackets). df['col']['row'] → one value.
Quick Check

What does df[['Name', 'IP Marks']] return?

Quick Check

Which safely selects a column named 'IP Marks'?