Ultimate access to all questions.
Upgrade Now 🚀
Sign in to unlock AI tutor
Given a DataFrame df with a column text containing sentences, how would you extract all occurrences of the word 'Spark' into a new column spark_occurrences using Spark? Provide the code snippet.
df
text
spark_occurrences
A
df.withColumn('spark_occurrences', size(split(col('text'), 'Spark'))) - 1
B
df.select(size(split(col('text'), 'Spark')) - 1)
C
df.withColumn('spark_occurrences', regexp_extract(col('text'), 'Spark', 0))
D
df.select(regexp_extract(col('text'), 'Spark', 0))