Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to get the row count of a Pandas DataFrame?

I'm trying to get the number of rows of dataframe df with Pandas, and here is my code.

Method 1:

total_rows = df.count
print total_rows + 1

Method 2:

total_rows = df['First_columnn_label'].count
print total_rows + 1

Both the code snippets give me this error:

TypeError: unsupported operand type(s) for +: 'instancemethod' and 'int'

What is wrong here?
by

2 Answers

kshitijrana14
Suppose df is your dataframe then:
count_row = df.shape[0]  # Gives number of rows
count_col = df.shape[1] # Gives number of columns

Or, more succinctly,
r, c = df.shape
sandhya6gczb
For the data frame df use any of the following to get row counts.

len(df.index)

 df.shape[0 ] 

 df[df.columns[0]].count() 

Login / Signup to Answer the Question.