How to Select Several Columns of a pandas DataFrame with a List
To work with only some of a table's columns, give pandas a list of their names inside the square brackets: df[["name", "city"]]. You get a smaller table back, with the columns in the order of your list. This guide does it with pandas 3.1.2 on Python 3.15.2.
Syntax
<smaller table> = <table>[["<column 1>", "<column 2>"]]
| Part | What it means |
|---|---|
The outer [ ] | Selects from the table |
The inner [ ] | A Python list of column names |
| The order of the names | The order of the columns in the result |
The indexing guide says: "You can pass a list of columns to [] to select columns in that order."
The Example
A table of two people has a name, a city and an age. The script keeps only the name and the city.
Prerequisites
- pandas in your project, for example with
uv add pandas. This guide uses pandas 3.1.2 on Python 3.15.2.
Step 1: Write the Script
import pandas as pd
people = pd.DataFrame(
{"name": ["Ada", "Grace"], "city": ["London", "New York"], "age": [36, 45]}
)
print(people[["name", "city"]])
![The several_columns.py script in a macOS-style code window: a people DataFrame with name, city and age, and print(people[["name", "city"]]).](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/pandas-several-columns-01-code.webp)
Step 2: Run It
uv run python several_columns.py
name city
0 Ada London
1 Grace New York

The age column is gone, and the original table is unchanged. The command works unchanged in PowerShell.
Choose the Order
The list sets the order. people[["city", "name"]] printed:
city name
0 London Ada
1 New York Grace
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Single brackets: people["name", "city"] | KeyError: ('name', 'city'): pandas looks for one column whose name is that pair | Use double brackets: people[["name", "city"]] |
A name that isn't a column: people[["name", "town"]] | KeyError: "['town'] not in index" | Check the names in people.columns |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
KeyError: ('name', 'city') | The names are in single brackets | Add the inner list brackets |
KeyError: "['...'] not in index" | One of the listed names doesn't exist | Fix the spelling; the error names the missing column |
FAQ
Does it change the original table?
No. It returns a new, smaller table. After smaller = people[["name", "city"]], list(people.columns) still printed ['name', 'city', 'age'].
Can I keep the list in a variable?
Yes, and that's common when the same columns are used in several places: columns = ["name", "city"], then people[columns].
Conclusion
people[["name", "city"]] returned a table with only those two columns, in the order of the list. Use double brackets, and read the KeyError to find a misspelled name.
Additional Resources
- Indexing and selecting data — selecting columns and rows.
- DataFrame.columns — the names to pick from.
