How to Get the Row Count of a Pandas Dataframe?
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.