您好,我使用以下命令从原始数据帧创建了分组数据帧:
sp2 = spark_df.drop_duplicates().groupBy('Transaction').agg(F.collect_list("Product").alias("items"))
我的spark_df
数据帧有三列:Transaction
、Products
和CustomerID
我想把CustomerID
列放入sp2
数据帧(它不会被分组)。你知道吗
当我尝试用这个命令连接它时:
df_joined = sp2.join(spark_df, "CustomerID")
我收到了这个错误信息:
Py4JJavaError: An error occurred while calling o44.join. : org.apache.spark.sql.AnalysisException: USING column
CustomerID
cannot be resolved on the left side of the join. The left-side columns: [Transaction, items];
发生此错误是因为在
sp2
数据帧中没有CustomerID
列。所以你不能在CustomerID
上加入他们。我建议您在sp2
数据帧中用None
值创建一个CustomerID
列,然后在CustomerID
列上用spark_df
连接它。你知道吗这是执行此操作的示例代码:
更新:向分组数据中添加
CustomerID
列的另一种方法是使用first
函数:相关问题 更多 >
编程相关推荐