Skip to content

DOC: "10 minutes to pandas" guide doesn't explain that double brackets return a DataFrame, not a Series #66616

Description

@devorech

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/user_guide/10min.html#getitem

Documentation problem

The "Getitem ([])" section of the "10 minutes to pandas" tutorial shows that a single label in brackets will return a Series:

df["A"]

It also shows that a list of multiple labels returns a DataFrame:

df[["B", "A"]]

It never shows the specific case of a list containing a single label (e.g. df[["A"]], which also returns a DataFrame). However, since df["A"] and df[["A"]] look nearly identical but return different object types, this could be a common point of confusion for beginners, yet isn't directly illustrated anywhere on this page. The distinction is already covered in the more comprehensive "Indexing and selecting data" guide, but it is not mentioned in the "10 minutes to pandas" tutorial, where many new users will actually first encounter column selection.

Suggested fix for documentation

Add a short note and example directly after the existing df[["B", "A"]] example, describing df[["A"]] and stating that it returns a DataFrame containing that one column, rather than a Series.

I would like to work on this myself, and plan submit a PR with the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions