How do I get the row count of a Pandas DataFrame?
You can use the shape
property of the DataFrame to get the number of rows and columns. The shape
property returns a tuple with the number of rows as the first element and the number of columns as the second element. To get the number of rows, you can do:
df = pd.read_csv('file.csv')
num_rows = df.shape[0]
Watch a video course
Python - The Practical Guide
Alternatively, you can use the len
function to get the number of rows:
num_rows = len(df)
You can also use the count
method to get the number of non-NA/null values in each column:
num_rows = df.count()
This will give you a Series with the row count for each column.