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

 收藏

I have column quantity in dataframe. I want to add a new column to this dataframe with each record having min("Quantity"). I am trying to use lit() in pyspark. something like below

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().

But, in place of 2 here, I want min(Quantity). Am I missing something?

回复