<jupyter_start><jupyter_text>Data Partitioning and Accessing data partitions<jupyter_code>pairs = sc.parallelize([1, 2, 3, 4, 5, 6, 7, 8]).map(lambda x: (x, x))

pairs.collect()

pairs.partitionBy(4).glom().collect()


# Get the coutn of data elements 
counts = pairs.count()
print(counts)


# First partition data based on number of batches. 
numberOfBatches = 4
partitionedRDD = pairs.partitionBy(int(counts/numberOfBatches)).glom()


# Then we can Loop through the model and train it. 
for i in range(4):
    
    sets = partitionedRDD.map(lambda x: x[i]).collect()
    print("Batch number  ", i, sets)
pairs.partitionBy(2).glom().collect()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13670133729569092, 'fraction_numerical': 0.017830609212481426, 'mean_word_length': 4.912280701754386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '182974', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 257, 'n_tokens_neox': 237, 'n_words': 63, 'path': 'Notebooks/Spark-Example-6-Data-Partitioning.ipynb', 'repo_name': 'MaxTeiger/BigDataAnalytics', 'size': '673'}