mars.dataframe.DataFrame.set_axis#
- DataFrame.set_axis(labels, axis=0, inplace=False)#
将期望的索引分配给给定的轴。
列或行标签的索引可以通过赋值给列表或索引来更改。
- Parameters
- 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