Obviously new to Pandas. How can i simply count the number of records in a dataframe.
I would have thought some thing as simple as this would do it and i can't seem to even find the answer in searches…probably because it is too simple.
cnt = df.count
print cnt
the above code actually just prints the whole df
Best Answer
To get the number of rows in a dataframe use:
(and
df.shape[1]
to get the number of columns).As an alternative you can use
or
(and
len(df.columns)
for the columns)shape
is more versatile and more convenient thanlen()
, especially for interactive work (just needs to be added at the end), butlen
is a bit faster (see also this answer).To avoid:
count()
because it returns the number of non-NA/null observations over requested axislen(df.index)
is fasterdf.__len__
is just a call tolen(df.index)
Why you should not use
count()