File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
75
75
-i " pandas.MultiIndex.names SA01" \
76
76
-i " pandas.MultiIndex.remove_unused_levels RT03,SA01" \
77
77
-i " pandas.MultiIndex.reorder_levels RT03,SA01" \
78
- -i " pandas.MultiIndex.set_levels RT03,SA01" \
79
78
-i " pandas.MultiIndex.sortlevel PR07,SA01" \
80
79
-i " pandas.MultiIndex.to_frame RT03" \
81
80
-i " pandas.NA SA01" \
Original file line number Diff line number Diff line change @@ -933,6 +933,19 @@ def set_levels(
933
933
"""
934
934
Set new levels on MultiIndex. Defaults to returning new index.
935
935
936
+ The `set_levels` method provides a flexible way to change the levels of a
937
+ `MultiIndex`. This is particularly useful when you need to update the
938
+ index structure of your DataFrame without altering the data. The method
939
+ returns a new `MultiIndex` unless the operation is performed in-place,
940
+ ensuring that the original index remains unchanged unless explicitly
941
+ modified.
942
+
943
+ The method checks the integrity of the new levels against the existing
944
+ codes by default, but this can be disabled if you are confident that
945
+ your levels are consistent with the underlying data. This can be useful
946
+ when you want to perform optimizations or make specific adjustments to
947
+ the index levels that do not strictly adhere to the original structure.
948
+
936
949
Parameters
937
950
----------
938
951
levels : sequence or list of sequence
@@ -945,6 +958,14 @@ def set_levels(
945
958
Returns
946
959
-------
947
960
MultiIndex
961
+ A new `MultiIndex` with the updated levels.
962
+
963
+ See Also
964
+ --------
965
+ MultiIndex.set_codes : Set new codes on the existing `MultiIndex`.
966
+ MultiIndex.remove_unused_levels : Create new MultiIndex from current that
967
+ removes unused levels.
968
+ Index.set_names : Set Index or MultiIndex name.
948
969
949
970
Examples
950
971
--------
You can’t perform that action at this time.
0 commit comments