Complete the code to cache the DataFrame for faster reuse.
df = spark.read.csv('data.csv') df.[1]()
Caching the DataFrame stores it in memory to speed up repeated operations, preventing delays in production.
Complete the code to repartition the DataFrame for better parallelism.
df = df.[1](10)
Repartitioning changes the number of partitions to improve parallel processing and avoid bottlenecks.
Fix the error in the code to avoid driver memory overflow by limiting data collected.
sample_data = df.limit([1]).collect()Collecting a small limit like 100 prevents driver memory overload and costly failures.
Fill both blanks to create a broadcast join to optimize shuffle and memory use.
from pyspark.sql.functions import broadcast joined_df = df1.join([1](df2), 'id') joined_df.[2]()
Broadcasting the smaller DataFrame reduces shuffle. Showing the result triggers the action.
Fill both blanks to create a dictionary of word counts filtering words longer than 3 letters.
words = ['spark', 'data', 'science', 'ai', 'ml'] word_counts = {word: [1] for word in words if len(word) [2] 3}
This dictionary comprehension counts letters of words longer than 3 characters, helping tune data filtering.
