<jupyter_start><jupyter_text>Spark RDD transformations 1. **map(func)** Returns a new distributed dataset formed by passing each element of the source through a function func<jupyter_code>rdd = sc.parallelize(["b", "a", "c"])
sorted(rdd.map(lambda x: (x, 1)).collect())<jupyter_output><empty_output><jupyter_text>2. **filter(func)**Return a new dataset formed by selecting those elements of the source on which func returns true<jupyter_code>rdd = sc.parallelize([1, 4, 7, 8, 9])

# Filter all of the numbers divisible by 2
rdd.filter(lambda x: x % 2 == 0).collect()<jupyter_output><empty_output><jupyter_text>3. **flatMap(func)**Similar to map, but each input item can be mapped to 0 or more output items (so func should return a Seq rather than a single item)<jupyter_code>rdd.flatMap(lambda x: range(1, x)).collect()<jupyter_output><empty_output><jupyter_text>4. **union(rdd)**Build the union of a list of RDDs.<jupyter_code>rdd = sc.parallelize([1, 2, 3])

# Union the above RDD with itself. 
rdd.union(rdd).collect()<jupyter_output><empty_output><jupyter_text>5. **distinct([numPartitions])**Returns a new RDD containing the distinct elements in this RDD.<jupyter_code>sc.parallelize([1, 1, 1, 2, 3]).distinct().collect()<jupyter_output><empty_output><jupyter_text>6. **cartesian(other)**Return the Cartesian product of this RDD and another one, that is, the RDD of all pairs of elements (a, b) where a is in self and b is in other.<jupyter_code>rdd.cartesian(rdd).collect()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1318754141815772, 'fraction_numerical': 0.01656726308813784, 'mean_word_length': 6.783505154639175, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '255330', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 538, 'n_tokens_neox': 518, 'n_words': 158, 'path': 'Notebooks/Spark-Example-03.ipynb', 'repo_name': 'Miked387/big_data', 'size': '1509'}