pyspark.RDD.subtractByKey

RDD.subtractByKey(other: pyspark.rdd.RDD[Tuple[K, Any]], numPartitions: Optional[int] = None) → pyspark.rdd.RDD[Tuple[K, V]][source]

Return each (key, value) pair in self that has no pair with matching key in other.

Examples

>>> x = sc.parallelize([("a", 1), ("b", 4), ("b", 5), ("a", 2)])
>>> y = sc.parallelize([("a", 3), ("c", None)])
>>> sorted(x.subtractByKey(y).collect())
[('b', 4), ('b', 5)]