How do I get the number of rows of a panda's data frame df?

How do I get the number of rows of a panda’s data frame df?

You can use the len() function. This will return the total number of rows in the DataFrame.

num_rows = len(df)

Hi,

The shape attribute returns a tuple (n_rows, n_columns), so accessing the first element [0] gives the number of rows.

num_rows = df.shape[0]

One way is to use the count() method that returns the number of non-null values in each DataFrame column.

Since you’re counting non-null values, any column will do, and taking the count of the first column [0] gives the total number of rows.

num_rows = df.count()[0]