Skip to content

DOC: No warning in set_index() that previous index column is removed. #60973

Closed
@ncotie

Description

@ncotie

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/reference/api/pandas.DataFrame.set_index.html

Documentation problem

set_index(), when applied to a DataFrame which already has a data column (non-default) assigned as index, will delete this data column from the DataFrame when assigning another data column to be the index.

While I find this behaviour inappropriate, I understand that reset_index() should be used before set_index(), in which case the original index column may be preserved.

The problem is that the documentation for set_index() does not mention this at all, so the user is left to discover the problem and then the way to avoid it.

Suggested fix for documentation

Add a comment in the set_index documentation to clarify that setting a data column as index, when there is already a different data column serving as index, will delete that data column, unless reset_index is performed first.

Metadata

Metadata

Assignees

Labels

DocsIndexingRelated to indexing on series/frames, not to indexes themselvesNeeds DiscussionRequires discussion from core team before further action

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions