當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pyspark Series.swaplevel用法及代碼示例

本文簡要介紹 pyspark.pandas.Series.swaplevel 的用法。

用法:

Series.swaplevel(i: Union[int, Any, Tuple[Any, …]] = - 2, j: Union[int, Any, Tuple[Any, …]] = - 1, copy: bool = True) → pyspark.pandas.series.Series

在 MultiIndex 中交換級別 i 和 j。默認是交換索引的兩個最內層。

參數

i, j整數,字符串

要交換的索引的級別。可以將級別名稱作為字符串傳遞。

copy布爾值,默認為真

是否複製底層數據。必須為真。

返回

Series

在 MultiIndex 中交換級別的係列。

例子

>>> midx = pd.MultiIndex.from_arrays([['a', 'b'], [1, 2]], names = ['word', 'number'])
>>> midx  
MultiIndex([('a', 1),
            ('b', 2)],
           names=['word', 'number'])
>>> psser = ps.Series(['x', 'y'], index=midx)
>>> psser
word  number
a     1         x
b     2         y
dtype: object
>>> psser.swaplevel()
number  word
1       a       x
2       b       y
dtype: object
>>> psser.swaplevel(0, 1)
number  word
1       a       x
2       b       y
dtype: object
>>> psser.swaplevel('number', 'word')
number  word
1       a       x
2       b       y
dtype: object

相關用法


注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.Series.swaplevel。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。