Getting the count of records in a data frame quickly

thunderhemu picture thunderhemu · Sep 6, 2016 · Viewed 99.5k times · Source

I have a dataframe with as many as 10 million records. How can I get a count quickly? df.count is taking a very long time.

Answer

Ravi picture Ravi · Aug 9, 2018

It's going to take so much time anyway. At least the first time.

One way is to cache the dataframe, so you will be able to more with it, other than count.

E.g

df.cache()
df.count()

Subsequent operations don't take much time.