LambdaLab
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
Key Takeaway
df['col'] → one column as a Series. df[['a', 'b']] → several columns as a DataFrame. Note the double brackets.
Quick Check

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

Quick Check

Which safely selects a column named 'IP Marks'?