pyspark.pandas.Index.copy

Index.copy(name: Union[Any, Tuple[Any, …], None] = None, deep: Optional[bool] = None) → pyspark.pandas.indexes.base.Index

Make a copy of this object. name sets those attributes on the new object.

Parameters
namestring, optional

to set name of index

deepNone

this parameter is not supported but just dummy parameter to match pandas.

Examples

>>> df = ps.DataFrame([[1, 2], [4, 5], [7, 8]],
...                   index=['cobra', 'viper', 'sidewinder'],
...                   columns=['max_speed', 'shield'])
>>> df
            max_speed  shield
cobra               1       2
viper               4       5
sidewinder          7       8
>>> df.index
Index(['cobra', 'viper', 'sidewinder'], dtype='object')

Copy index

>>> df.index.copy()
Index(['cobra', 'viper', 'sidewinder'], dtype='object')

Copy index with name

>>> df.index.copy(name='snake')
Index(['cobra', 'viper', 'sidewinder'], dtype='object', name='snake')