pyspark.RDD.takeSample

RDD.takeSample(withReplacement: bool, num: int, seed: Optional[int] = None) → List[T][source]

Return a fixed-size sampled subset of this RDD.

Notes

This method should only be used if the resulting array is expected to be small, as all the data is loaded into the driver’s memory.

Examples

>>> rdd = sc.parallelize(range(0, 10))
>>> len(rdd.takeSample(True, 20, 1))
20
>>> len(rdd.takeSample(False, 5, 2))
5
>>> len(rdd.takeSample(False, 15, 3))
10