The shape property in Pandas

The shape property of a pandas Series and DataFrame returns a tuple containing the number of rows and columns in the format: (nrows, ncolumns).

Note: As shape is a property so do not use parentheses with it.

Syntax a) DataFrame.shape
b) Series.shape

Example: Creating a Series.

Python

data = [100, 200, 300, 500, 700]
newseries = pd.Series(data)
print(newseries)  

The output of the above code is a pandas’ series. Now we want to see the shape of the series.

Python

print(newseries.shape)

The output of the above code is (5,) as shown in the image below.

The shape property in Pandas

As series is a single dimensional data so that is why we are not able to see the number of columns in the output.

Example: Let’s use a dataframe and get its shape.

Python

mydata=pd.read_csv("employees.csv")
print(mydata.shape)

The output of the above code is (9,5).