[ Web Proxy ]
URL:
Viewing: https://spark.apache.org/docs/latest/api/python/reference/api/pyspark.RDD.mapValues.html [Back]  [Original]

pyspark.RDD.mapValues — PySpark 4.2.0 documentation Skip to main content
Search the docs ...:

pyspark.RDD.mapValues#

RDD.mapValues(f)[source]#

Pass each value in the key-value pair RDD through a map function without changing the keys; this also retains the original RDDs partitioning.

New in version 0.7.0.

Parameters
ffunction

a function to turn a V into a U

Returns
RDD

a RDD containing the keys and the mapped value

Examples

>>> rdd = sc.parallelize([("a", ["apple", "banana", "lemon"]), ("b", ["grapes"])])
>>> def f(x): return len(x)
...
>>> rdd.mapValues(f).collect()
[('a', 3), ('b', 1)]

Web Proxy Viewer  |  New URL  |  Original Page