pyspark.pandas.Index.repeat#

Index.repeat(repeats)[source]#

Repeat elements of a Index/MultiIndex.

Returns a new Index/MultiIndex where each element of the current Index/MultiIndex is repeated consecutively a given number of times.

Parameters
repeatsint

The number of repetitions for each element. This should be a non-negative integer. Repeating 0 times will return an empty Index.

Returns
repeated_indexIndex/MultiIndex

Newly created Index/MultiIndex with repeated elements.

See also

Series.repeat

Equivalent function for Series.

Examples

>>> idx = ps.Index(['a', 'b', 'c'])
>>> idx
Index(['a', 'b', 'c'], dtype='object')
>>> idx.repeat(2)
Index(['a', 'b', 'c', 'a', 'b', 'c'], dtype='object')

For MultiIndex,

>>> midx = ps.MultiIndex.from_tuples([('x', 'a'), ('x', 'b'), ('y', 'c')])
>>> midx  
MultiIndex([('x', 'a'),
            ('x', 'b'),
            ('y', 'c')],
           )
>>> midx.repeat(2)  
MultiIndex([('x', 'a'),
            ('x', 'b'),
            ('y', 'c'),
            ('x', 'a'),
            ('x', 'b'),
            ('y', 'c')],
           )
>>> midx.repeat(0)  
MultiIndex([], )