How to Get One Column of a pandas DataFrame
A DataFrame is a table, and most work starts by taking one column out of it: the prices, the dates, the page counts. In pandas you write the column's name in square brackets, and you get a Series, a single column with its row labels. This guide does it with pandas 3.1.2 on Python 3.15.2.
Syntax
<column> = <table>["<column name>"]
| Part | What it means |
|---|---|
<table> | A pandas DataFrame |
["<column name>"] | The name of one column, exactly as it's spelled in the table |
<column> | The result: a Series |
The indexing guide lists frame[colname] with the result "Series corresponding to colname".
The Example
A table of three books has a title and a pages column. The script takes the pages column and prints it and its type.
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
books = pd.DataFrame({"title": ["Dune", "Emma", "Ulysses"], "pages": [412, 474, 730]})
pages = books["pages"]
print(pages)
print(type(pages).__name__)
![The one_column.py script in a macOS-style code window: a books DataFrame with title and pages, pages = books["pages"], then two prints.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/pandas-one-column-01-code.webp)
Step 2: Run It
uv run python one_column.py
0 412
1 474
2 730
Name: pages, dtype: int64
Series

The result is a Series: the row labels on the left, the values on the right, and its name and type at the bottom. The command works unchanged in PowerShell.
One Column as a Table
Double brackets, books[["pages"]], return a one-column DataFrame instead:
pages
0 412
1 474
2 730
DataFrame
Use single brackets for a list of values, and double brackets when the next step needs a table.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Misspelling the name: books["page"] | A long traceback that ends in KeyError: 'page' | Copy the name from books.columns |
| Expecting a table from single brackets | You get a Series, which has no column names to show | Use books[["pages"]] |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
KeyError: '<name>' at the end of a long traceback | No column has exactly that name; capitals and spaces count | Print books.columns and copy the name |
FAQ
Can I write books.pages instead?
Yes, for simple names: books.pages.tolist() printed [412, 474, 730]. The indexing guide lists the limits: "You can use this access only if the index element is a valid Python identifier", and "The attribute will not be available if it conflicts with an existing method name". Square brackets work for every name, so they're the safer habit.
How do I get the values as a Python list?
With .tolist(), as above.
Conclusion
books["pages"] returned the pages column as a Series, named pages with type int64. Double brackets return a one-column table, and a misspelled name ends in a KeyError.
Additional Resources
- Indexing and selecting data — every way to pick columns and rows.
- Series — what you can do with the column you got.
