Python | Pandas Index.get_values ​​()



Index.get_values() Pandas Index.get_values() returns index data as numpy.ndarray … Returns a one-dimensional array for a multi-index array.

Syntax: Index.get_values ​​()

Returns: A one- dimensional numpy array of the Index values ​​

Example # 1: Use Index.get_values ​​() to return the index value as an array.

# import pandas as pd

import pandas as pd

 
# Create an index

idx = pd.Index ([ `Labrador` , ` Beagle` , ` Labrador` ,

< code class = "undefined spaces">  `Lhasa` , ` Husky ` , ` Beagle` ])

 
# Print index
idx

Output:

Let`s use Index.get_values ​​() to return the index data as an array.

# Returns the index marks as an array
idx.get_values ​​()

Output:

As we can see in the output, Index.get_values ​​() returned index labels as a numpy array.

Example # 2: Use Index.get_values ​​() for a multi-index array.

# import pandas as pd

import pandas as pd

 
# Create MultiIndex object

midx = pd.MultiIndex.from_arrays ([[ `Mon` , `Tue` , ` Wed` , `Thr` ],

[ 10 , 20 , 30 , 40 ]], names = ( `Days` , ` Target` ))

 
# Print the MultiIndex object
midx

Output:

Let`s return the index labels to one-dimensional array format.

# Convert multi-index to one  
# array size.
midx.get_values ​​()

Output:

As we can see in the output, even the multi-index was converted to a one-dimensional array.