Pandas Shape Function

The shape property is used to get a tuple representing the dimensionality of the Pandas DataFrame.

Pandas df.shape Syntax

Syntax: dataframe.shape
Return : Returns tuple of shape (Rows, columns) of dataframe/series

Example

This code uses pandas to read “nba.csv” and It then calculates and prints the shape of the DataFrame, which includes the number of rows and columns.

Python3




# importing pandas module
import pandas as pd
 
# importing csv file
data = pd.read_csv("nba.csv")
 
# using dataframe.shape
shape = data.shape
 
# printing shape
print("Shape = {}".format(shape))


Output:

Shape = (458, 9)

Pandas df.size, df.shape and df.ndim Methods

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas size, shape, and ndim methods are used to return the size, shape, and dimensions of data frames and series.

Dataset Used

To download the data set used in the following example, click here. In the following examples, the data frame used contains data from some NBA players.

Similar Reads

Pandas Size Function

The size property is used to get an int representing the number of elements in this object and Return the number of rows if Series. Otherwise, return the number of rows times the number of columns if DataFrame....

Pandas Shape Function

...

Pandas ndim Function

The shape property is used to get a tuple representing the dimensionality of the Pandas DataFrame....