df1 and df2 joined on columns id and category using inner join, what is the output of the following code?from pyspark.sql import SparkSession spark = SparkSession.builder.getOrCreate() data1 = [(1, 'A', 100), (2, 'B', 200), (3, 'A', 300)] data2 = [(1, 'A', 'X'), (2, 'B', 'Y'), (2, 'C', 'Z')] df1 = spark.createDataFrame(data1, ['id', 'category', 'value1']) df2 = spark.createDataFrame(data2, ['id', 'category', 'value2']) joined_df = df1.join(df2, on=['id', 'category'], how='inner') result = joined_df.collect()
df1 with df2 on columns id and category, how many rows will the resulting DataFrame have?from pyspark.sql import SparkSession spark = SparkSession.builder.getOrCreate() data1 = [(1, 'A', 100), (2, 'B', 200), (3, 'A', 300)] data2 = [(1, 'A', 'X'), (2, 'B', 'Y'), (2, 'C', 'Z')] df1 = spark.createDataFrame(data1, ['id', 'category', 'value1']) df2 = spark.createDataFrame(data2, ['id', 'category', 'value2']) joined_df = df1.join(df2, on=['id', 'category'], how='left') count = joined_df.count()
df1.join(df2, on='id,category', how='inner')
sales with columns store_id, date, sales_amount and targets with columns store_id, date, target_amount. You want to keep all sales records and add target amounts where available. Which join type should you use on columns store_id and date?on list (e.g., ['id', 'category'] vs ['category', 'id']) affect the join result?