pandas.DataFrame.shape[0] Method
This method usually works without an index and it is used to find the total number of rows and columns in a DataFrame, but to find the number of rows specifically, 0 is given as an index. Also, to find the number of columns, 1 is given as an index.
Syntax:
# Syntax for both rows and columns
df.shape()
# Syntax for rows
df.shape[0]
To work with Python Pandas, we need to import the pandas library. Below is the syntax,
import pandas as pd
Let us understand that how to get the number of rows in a DataFrame with the help of an example?
Output:
Explanation:
Here, we have created a DataFrame with four rows having index names Maths, Physics, Chemistry, and English respectively. df.shape[0] method will return the count of the number of rows hence the output is 4.
need an explanation for this answer? contact us directly to get an explanation for this answer