@@ -5868,10 +5868,6 @@ def set_index(
5868
5868
columns or arrays (of the correct length). The index can replace the
5869
5869
existing index or expand on it.
5870
5870
5871
- .. warning::
5872
- Setting a new index will remove the current index column,
5873
- unless you first call `reset_index`.
5874
-
5875
5871
Parameters
5876
5872
----------
5877
5873
keys : label or array-like or list of labels/arrays
@@ -5884,6 +5880,8 @@ def set_index(
5884
5880
Delete columns to be used as the new index.
5885
5881
append : bool, default False
5886
5882
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.
5887
5885
inplace : bool, default False
5888
5886
Whether to modify the DataFrame rather than creating a new one.
5889
5887
verify_integrity : bool, default False
@@ -5957,6 +5955,25 @@ def set_index(
5957
5955
2 4 4 2014 40
5958
5956
3 9 7 2013 84
5959
5957
4 16 10 2014 31
5958
+
5959
+ Append a column to the existing index:
5960
+
5961
+ >>> df.set_index("month", inplace=True)
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
5960
5977
"""
5961
5978
inplace = validate_bool_kwarg (inplace , "inplace" )
5962
5979
self ._check_inplace_and_allows_duplicate_labels (inplace )
0 commit comments