Index.
rename
Alter Index or MultiIndex name. Able to set new names without level. Defaults to returning a new index.
Name(s) to set.
Modifies the object directly, instead of creating a new Index or MultiIndex.
The same type as the caller or None if inplace is True.
Examples
>>> df = ps.DataFrame({'a': ['A', 'C'], 'b': ['A', 'B']}, columns=['a', 'b']) >>> df.index.rename("c") Int64Index([0, 1], dtype='int64', name='c')
>>> df.set_index("a", inplace=True) >>> df.index.rename("d") Index(['A', 'C'], dtype='object', name='d')
You can also change the index name in place.
>>> df.index.rename("e", inplace=True) >>> df.index Index(['A', 'C'], dtype='object', name='e')
>>> df b e A A C B
Support for MultiIndex
>>> psidx = ps.MultiIndex.from_tuples([('a', 'x'), ('b', 'y')]) >>> psidx.names = ['hello', 'pandas-on-Spark'] >>> psidx MultiIndex([('a', 'x'), ('b', 'y')], names=['hello', 'pandas-on-Spark'])
>>> psidx.rename(['aloha', 'databricks']) MultiIndex([('a', 'x'), ('b', 'y')], names=['aloha', 'databricks'])