Return a new RDD containing only the elements that satisfy a predicate. 1

Return a new RDD containing only the elements that satisfy a predicate.

rdd = sc.parallelize([1, 2, 3, 4, 5])
rdd.filter(lambda x: x % 2 == 0).collect()
# [2, 4]

Here is what the above code is Doing:
1. Create an RDD from a list of integers.
2. Filter out the odd numbers.
3. Return the result as a list.

Similar Posts