mars.dataframe.DataFrame.set_axis#

DataFrame.set_axis(labels, axis=0, inplace=False)#

将期望的索引分配给给定的轴。

列或行标签的索引可以通过赋值给列表或索引来更改。

Parameters
  • labels (类列表, 索引) – 新索引的值。

  • axis ({0'index', 1'columns'}, 默认为 0) – 要更新的轴。值 0 标识行,1 标识列。

  • inplace (bool, 默认值为 False) – 是否返回一个新的 DataFrame 实例。

Returns

重命名 – 一个类型为 DataFrame 的对象,或如果 inplace=True 则为 None。

Return type

DataFrame 或 无

另请参阅

DataFrame.rename_axis

更改索引或列的名称。

示例

>>> import mars.dataframe as md
>>> df = md.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})

更改行标签。

>>> df.set_axis(['a', 'b', 'c'], axis='index').execute()
   A  B
a  1  4
b  2  5
c  3  6

更改列标签。

>>> df.set_axis(['I', 'II'], axis='columns').execute()
   I  II
0  1   4
1  2   5
2  3   6

现在,在线更新标签。

>>> df.set_axis(['i', 'ii'], axis='columns', inplace=True)
>>> df.execute()
   i  ii
0  1   4
1  2   5
2  3   6