Skip to main content

How to Get One Column of a pandas DataFrame

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

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​

Syntax
<column> = <table>["<column name>"]
PartWhat 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​

one_column.py
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.

Step 2: Run It​

Terminal
uv run python one_column.py
Output
0 412
1 474
2 730
Name: pages, dtype: int64
Series

The terminal after uv run python one_column.py: the pages Series with 412, 474 and 730, Name: pages, dtype: int64, then 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:

Output
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​

MistakeWhat happensDo 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 bracketsYou get a Series, which has no column names to showUse books[["pages"]]

Troubleshooting​

SymptomLikely causeFix
KeyError: '<name>' at the end of a long tracebackNo column has exactly that name; capitals and spaces countPrint 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​