Pandas DataFrame row count in Python

David Y.

The Problem

How can I get the number of rows of a Pandas DataFrame in Python?

The Solution

We can do this in one of two main ways:

  1. Using Python’s built-in len() function:
    row_count = len(my_dataframe)
  2. Using the DataFrame.shape property, which contains a tuple of the row and column count:
    row_count = my_dataframe.shape[0]

The len() function is usually the faster of the two solutions, but shape may be useful in circumstances where we also need the column count.

Join the discussionCome work with us
Share on Twitter
Bookmark this page
Ask a questionImprove this Answer

Related Answers

A better experience for your users. An easier life for your developers.

    TwitterGitHubDribbbleLinkedin
© 2023 • Sentry is a registered Trademark
of Functional Software, Inc.