Skip to content

Commit 56847c5

Browse files
authored
DOC: Updated set_index doc with a warning (#60990)
* Updated set_index doc with a warning * Updated set_index parameter append along with an example * Updated set_index example for append * Updated set_index example
1 parent c1e57c9 commit 56847c5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/core/frame.py

+21
Original file line numberDiff line numberDiff line change
@@ -5880,6 +5880,8 @@ def set_index(
58805880
Delete columns to be used as the new index.
58815881
append : bool, default False
58825882
Whether to append columns to existing index.
5883+
Setting to True will add the new columns to existing index.
5884+
When set to False, the current index will be dropped from the DataFrame.
58835885
inplace : bool, default False
58845886
Whether to modify the DataFrame rather than creating a new one.
58855887
verify_integrity : bool, default False
@@ -5953,6 +5955,25 @@ def set_index(
59535955
2 4 4 2014 40
59545956
3 9 7 2013 84
59555957
4 16 10 2014 31
5958+
5959+
Append a column to the existing index:
5960+
5961+
>>> df = df.set_index("month")
5962+
>>> df.set_index("year", append=True)
5963+
sale
5964+
month year
5965+
1 2012 55
5966+
4 2014 40
5967+
7 2013 84
5968+
10 2014 31
5969+
5970+
>>> df.set_index("year", append=False)
5971+
sale
5972+
year
5973+
2012 55
5974+
2014 40
5975+
2013 84
5976+
2014 31
59565977
"""
59575978
inplace = validate_bool_kwarg(inplace, "inplace")
59585979
self._check_inplace_and_allows_duplicate_labels(inplace)

0 commit comments

Comments
 (0)