pyspark的lit()中的聚合函数以及withColumn

问题描述 投票:0回答:1

我在数据框中有列数。我想为此数据帧添加一个新列,每个记录都具有min("Quantity")。我正在尝试在lit()中使用pyspark。如下所示

df.withColumn("min_quant", lit(min(col("Quantity")))).show().

导致低于错误的结果

grouping expressions sequence is empty, and `InvoiceNo` is not an aggregate function. 
Wrap (min(`Quantity`) AS `min_quant`) in windowing function(s) or wrap 

这正在工作:

df.withColumn("min_quant", lit(2)).show().

但是,我要代替[2]。我想念什么吗?

apache-spark apache-spark-sql aggregate-functions pyspark-sql pyspark-dataframes
1个回答
0
投票

请尝试使用窗口函数,因为min()函数需要聚合。

min(Quantity)
© www.soinside.com 2019 - 2024. All rights reserved.