How to Get the Row Count of a Pandas Dataframe?

python

To get the row count of a pandas dataframe, the shape property can be used.

Here's an example:

import pandas as pd

# Create a dataframe
df = pd.DataFrame({'Column1': [1, 2, 3], 'Column2': ['A', 'B', 'C']})

# Get the row count using the shape property
row_count = df.shape[0]

print(f'The dataframe has {row_count} rows.')

Output:

The dataframe has 3 rows.

Alternatively, the len() function can also be used:

row_count = len(df)

print(f'The dataframe has {row_count} rows.')

Output:

The dataframe has 3 rows.

Latest Questions

python How to Fix ""zsh: command not found: python" Error on MacOS X? python How to Fix "xlrd.biffh.XLRDError: Excel xlsx file; not supported" Error in Pandas? python How to Remove All Whitespace From a Python String?