Skip to content

DOC: Updated set_index doc with a warning #60990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5880,6 +5880,8 @@ def set_index(
Delete columns to be used as the new index.
append : bool, default False
Whether to append columns to existing index.
Setting to True will add the new columns to existing index.
When set to False, the current index will be dropped from the DataFrame.
inplace : bool, default False
Whether to modify the DataFrame rather than creating a new one.
verify_integrity : bool, default False
Expand Down Expand Up @@ -5953,6 +5955,25 @@ def set_index(
2 4 4 2014 40
3 9 7 2013 84
4 16 10 2014 31

Append a column to the existing index:

>>> df = df.set_index("month")
>>> df.set_index("year", append=True)
sale
month year
1 2012 55
4 2014 40
7 2013 84
10 2014 31

>>> df.set_index("year", append=False)
sale
year
2012 55
2014 40
2013 84
2014 31
"""
inplace = validate_bool_kwarg(inplace, "inplace")
self._check_inplace_and_allows_duplicate_labels(inplace)
Expand Down
Loading