Python Pandas - Return a tuple of the shape of the underlying data


To return a tuple of the shape of the underlying data, use the index.shape property in Pandas.

At first, import the required libraries −

import pandas as pd

Creating the index −

index = pd.Index(['Car','Bike','Truck','Car','Airplane'])

Display the index −

print("Pandas Index...\n",index)

Return a tuple of the shape of the underlying data −

print("\nA tuple of the shape of underlying data...\n",index.shape)

Example

Following is the code −

import pandas as pd

# Creating the index
index = pd.Index(['Car','Bike','Truck','Car','Airplane'])

# Display the index
print("Pandas Index...\n",index)

# Return an array representing the data in the Index
print("\nArray...\n",index.values)

# Return a tuple of the shape of the underlying data
print("\nA tuple of the shape of underlying data...\n",index.shape)

Output

This will produce the following code −

Pandas Index...
Index(['Car', 'Bike', 'Truck', 'Car', 'Airplane'], dtype='object')

Array...
['Car' 'Bike' 'Truck' 'Car' 'Airplane']

A tuple of the shape of underlying data...
(5,)

Updated on: 13-Oct-2021

457 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements