Change language

Python | Pandas Index.repeat ()

| |

Index.repeat() Pandas Index.repeat() repeats index items. The function returns a new index, where each element of the current index is repeated a specified number of times.

Syntax: Index.repeat (repeats, * args, ** kwargs)

Parameters:
repeats: The number of repetitions for each element.
** kwargs: Additional keywords have no effect but might be accepted for compatibility with numpy.

Returns: Newly created Index with repeated elements.

Example # 1: Use Index.repeat () () to repeat index items 2 times.

# import pandas as pd

import pandas as pd

 
# Create index

idx = pd.Index ([ ’Beagle’ , ’Pug’ , ’Labrador’ , ’ Pug’ ,

’Mastiff’ , None , ’Beagle’ ])

 
# Print index
idx

Output:

Let’s repeat the index items 2 times.

 

# repeat values ​​

idx.repeat ( 2 )

Output:

As we can see in the output, the function returned a new index with all values ​​repeated 2 times. It’s important to note that the function also repeated the NaN value.

Example # 2: Use Index.repeat () to repeat index value 3 times.

# import pandas as pd

import pandas as pd

 
# Index creation

idx = pd.Index ([ 22 , 14 , 8 , 56 , None , 21 , None , 23 ])

 
# Print index
idx

Output:

Let’s repeat the index items 3 times.

# repeat values ​​

idx.repeat ( 3 )

Exit:

As we can see in the output, the function returned a new index with all values, repeated 3 times. It’s important to note that the function also repeated the NaN value.

Python | Pandas Index.repeat () NumPy: Questions

Python | Pandas Index.repeat () Python functions: Questions

Shop

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method