Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyspark RDD collect first 163 Rows

Is there a way to get the first 163 rows of an rdd without converting to a df?

I've tried something like newrdd = rdd.take(163), but that returns a list, and rdd.collect() returns the whole rdd.

Is there a way to do this? Or if not is there a way to convert a list into an rdd?

like image 892
wheels Avatar asked Dec 11 '22 19:12

wheels


1 Answers

It is not very efficient but you can zipWithIndex and filter:

rdd.zipWithIndex().filter(lambda vi: vi[1] < 163).keys()

In practice it make more sense to simply take and parallelize:

sc.parallelize(rdd.take(163))
like image 198
zero323 Avatar answered Dec 30 '22 08:12

zero323