pyspark.RDD.foreachPartition

RDD.foreachPartition(f: Callable[[Iterable[T]], None]) → None

Applies a function to each partition of this RDD.

Examples

>>> def f(iterator):
...     for x in iterator:
...          print(x)
>>> sc.parallelize([1, 2, 3, 4, 5]).foreachPartition(f)