How to get the row count of a Pandas DataFrame?

PandasServer Side ProgrammingProgramming

To get the row count of a Pandas DataFrame, we can use the length of DataFrame index.

Steps

  • Create a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.

  • Print the input DataFrame.

  • Print the length of the DataFrame index list, len(df.index).

Example

 Live Demo

import pandas as pd

df = pd.DataFrame(
   {
      "x": [5, 2, 1, 9],
      "y": [4, 1, 5, 10],
      "z": [4, 1, 5, 0]
   }
)

print "Input DataFrame is:\n", df
print "Row count of DataFrame is: ", len(df.index)

Output

Input DataFrame is:
   x  y  z
0  5  4  4
1  2  1  1
2  1  5  5
3  9 10  0
Row count of DataFrame is: 4
raja
Published on 30-Aug-2021 09:21:30
Advertisements