maxframe.dataframe.DataFrame.set_axis#
- DataFrame.set_axis(labels, axis=0, inplace=False)#
为给定轴分配所需的索引。
通过分配一个类列表或 Index 对象,可以更改列或行标签的索引。
- 参数:
- 返回:
renamed -- 类型为 DataFrame 的对象,如果
inplace=True则返回 None。- 返回类型:
DataFrame or None
参见
DataFrame.rename_axis更改索引或列的名称。
示例
>>> import maxframe.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