Pandas Series: repeat() function

Repeat elements of a Pandas series

The repeat() function is used to repeat elements of a Series.

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


Series.repeat(self, repeats, axis=None)
Pandas Series repeat image
Name Description Type/Default Value Required / Optional
repeats The number of repetitions for each element. This should be a non-negative integer. Repeating 0 times will return an empty Series. int or array of ints Required
axis Must be None. Has no effect but is accepted for compatibility with numpy. Default Value: None Required

Returns: Series- Newly created Series with repeated elements.


Download the above Notebook from here.

Previous: Find indices where elements should be inserted to maintain order
Next: Squeeze 1 dimensional axis objects into scalars