PySpark 面接の質問と回答
質問 16. How can you perform a union operation on two DataFrames in PySpark?
You can use the 'union' method to combine two DataFrames with the same schema.
Example:
result = df1.union(df2)
質問 17. Explain the purpose of the 'window' function in PySpark.
The 'window' function is used for defining windows over data based on partitioning and ordering, often used with aggregation functions.
Example:
from pyspark.sql.window import Window
from pyspark.sql.functions import sum
window_spec = Window.partitionBy('category').orderBy('value')
result = df.withColumn('sum_value', sum('value').over(window_spec))
質問 18. What is the purpose of the 'explode' function in PySpark?
The 'explode' function is used to transform a column with arrays or maps into multiple rows, duplicating the values of the other columns.
Example:
from pyspark.sql.functions import explode
exploded_df = df.select('ID', explode('items').alias('item'))
質問 19. Explain the concept of 'broadcast' variables in PySpark.
'Broadcast' variables are read-only variables cached on each node of a cluster to efficiently distribute large read-only data structures.
Example:
from pyspark.sql.functions import broadcast
result = df1.join(broadcast(df2), 'key')
質問 20. How can you handle missing or null values in a PySpark DataFrame?
You can use the 'na' functions like 'drop' or 'fill' to handle missing values in a PySpark DataFrame.
Example:
df.na.drop()
ユーザー評価で最も役立つ内容: