pandas.Series.rename#
- Series.rename(index=None, *, axis=None, copy=True, inplace=False, level=None, errors='ignore')[源代码]#
更改系列索引标签或名称。
函数/DICT值必须唯一(1对1)。词典/系列中未包含的标签将保留原样。列出的额外标签不会引发错误。
或者,改变
Series.name
具有标量值的。请参阅 user guide 想要更多。
- 参数
- axis{0或“索引”}
未使用过的。仅为与DataFrame方法兼容而接受。
- index标量、可散列序列、类词典或函数,可选
函数或类DICT是应用于索引的转换。标量或类似Hasable的序列将改变
Series.name
属性。- **kwargs
传递给函数的其他关键字参数。只使用“inplace”关键字。
- 退货
- 系列或无
如果索引标签或名称已更改,则序列为None
inplace=True
。
参见
DataFrame.rename
对应的DataFrame方法。
Series.rename_axis
设置轴的名称。
示例
>>> s = pd.Series([1, 2, 3]) >>> s 0 1 1 2 2 3 dtype: int64 >>> s.rename("my_name") # scalar, changes Series.name 0 1 1 2 2 3 Name: my_name, dtype: int64 >>> s.rename(lambda x: x ** 2) # function, changes labels 0 1 1 2 4 3 dtype: int64 >>> s.rename({1: 3, 2: 5}) # mapping, changes labels 0 1 3 2 5 3 dtype: int64