mars.dataframe.Series.rename#

Series.rename(index=None, *, axis='index', copy=True, inplace=False, level=None, errors='ignore')#

更改系列索引标签或名称。

函数 / 字典值必须唯一(1对1)。未包含在字典 / 系列中的标签将保持不变。列出的额外标签不会导致错误。

或者,用标量值替换 Series.name

Parameters
  • axis ({0"index"}) – 未使用。仅为与DataFrame方法的兼容而接受。

  • index (标量, 可哈希序列, 类字典函数, 可选) – 函数或类字典是应用于索引的转换。 标量或可哈希序列将改变 Series.name 属性。

  • **kwargs – 传递给函数的额外关键字参数。仅使用“inplace”关键字。

Returns

系列的索引标签或名称已更改。

Return type

系列

另请参阅

DataFrame.rename

对应的 DataFrame 方法。

Series.rename_axis

设置轴的名称。

示例

>>> import mars.dataframe as md
>>> s = md.Series([1, 2, 3])
>>> s.execute()
0    1
1    2
2    3
dtype: int64
>>> s.rename("my_name").execute()  # scalar, changes Series.name.execute()
0    1
1    2
2    3
Name: my_name, dtype: int64
>>> s.rename(lambda x: x ** 2).execute()  # function, changes labels.execute()
0    1
1    2
4    3
dtype: int64
>>> s.rename({1: 3, 2: 5}).execute()  # mapping, changes labels.execute()
0    1
3    2
5    3
dtype: int64