logo

Selecting Columns in Pandas

To work with specific columns, you need to select them. Single column selection uses bracket notation with the column name.

df['name']

This returns a Series (a single column). For a DataFrame with one column, use double brackets:

df[['name']]

Multiple columns require a list of names:

df[['name', 'age', 'city']]

The order in your list determines the column order in the result. This is useful for reordering columns or selecting a subset for export.

I cover advanced column operations in my Pandas course.