0 votes
1 view
in Python by (11.5k points)

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 am I doing wrong?

1 Answer

0 votes
by (107k points)
  • You should use .shape method to get the output or len(DataFrame.index). However len(DataFrame.index) will be the fastest way to get the answer.

import numpy as np

import pandas as pd 

df = pd.DataFrame(np.arange(12).reshape(4,3))

df.shape

len(df.index)

image

 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...