How to Get the Number of Rows in a Pandas Dataframe

Spread the love

Problem –

You have a pandas dataframe and you want to know how many rows of data you have in that dataframe.

Solution –

There are many ways finding the number of rows in a pandas dataframe. Let’s read a dataset to illustrate.

import pandas as pd

df = pd.read_csv('')

To know the number of rows in a pandas dataframe, we can use the dataframe.shape attribute. The dataframe.shape attribute returns a tuple of the number of rows and columns in a dataframe (nrows, ncolumns).

out - (300, 3)

This dataframe has 300 rows and 3 columns. If you only want the rows or the columns then you can write like this.

# get me only rows count

# get me only column counts

Another method for finding the number of rows in a dataframe is using the len() function in python.

out - 300

Rating: 1 out of 5.

Leave a Reply