pandas.Series.reorder_levels#

Series.reorder_levels(order)[源代码][源代码]#

使用输入顺序重新排列索引级别。

不得删除或重复级别。

参数:
order表示新级别顺序的整数列表

按编号或键引用级别。

返回:
Series

Type of caller with index as MultiIndex (new object).

参见

DataFrame.reorder_levels

Rearrange index or column levels using input order.

例子

>>> arrays = [
...     np.array(["dog", "dog", "cat", "cat", "bird", "bird"]),
...     np.array(["white", "black", "white", "black", "white", "black"]),
... ]
>>> s = pd.Series([1, 2, 3, 3, 5, 2], index=arrays)
>>> s
dog   white    1
      black    2
cat   white    3
      black    3
bird  white    5
      black    2
dtype: int64
>>> s.reorder_levels([1, 0])
white  dog     1
black  dog     2
white  cat     3
black  cat     3
white  bird    5
black  bird    2
dtype: int64