Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the faster way to count the number of entries in a data frame?

I have a data frame df that contains around 1 Gb of data. Why the command df.count() takes a relatively long time to complete, while df.filter(...) is much faster? Is there any better way to estimate the number of entries in df that is faster than df.count()'

like image 391
Dinosaurius Avatar asked May 24 '17 08:05

Dinosaurius


1 Answers

df.count() is the correct way. Note that df.filter(...) is a transformation, which means it is lazy, i.e. the filtering code isn't executed yet. It will only be executed if you add an actiton like count or collect to the filtered result. And then the runtime should be similar to the original call to count.

like image 79
Harald Gliebe Avatar answered Sep 23 '22 08:09

Harald Gliebe