Pyspark 获取关联国家/地区的最小值

Pyspark 获取关联国家/地区的最小值,pyspark,Pyspark,我有一个包含国家、地区、价值、产品的数据集。需要使用最小值作为速度列获取最小值x和区域国家/地区 数据集 我希望每个产品在所有客户中的最小价值。为此,我一组一组地做了 cust Country Region value product min_x 100 france europe 1 x 1 101 france europe 2 x 1 102 poland europe 3 x 1 103 poland eu

我有一个包含国家、地区、价值、产品的数据集。需要使用最小值作为速度列获取最小值x和区域国家/地区

数据集 我希望每个产品在所有客户中的最小价值。为此,我一组一组地做了

cust    Country Region  value   product min_x
 100    france  europe  1   x   1
 101    france  europe  2   x   1
 102    poland  europe  3   x   1
 103    poland  europe  3   y   3
 104    france  europe  4   y   3
 105    france  europe  5   y   3



 df = spark.read.csv('dataset',header=True)
 df1 = df.groupBy('Product').agg(min(df.value).alias('min_x))

还需要一个具有最小值为x的区域国家/地区的列。加入时无法获得国家和地区的值。

我找到了解决方案

df = spark.read.csv(path,header=True)
w1 = Window.partitionBy(df.product).orderBy(df.value.desc())
df = df.withColumn('min_x',min(df.value).over(w1)).\
        withColumn('region_country',concat_ws('_',first('region'),first('country')))

可能与我链接的帖子相同的概念重复,但使用
pyspark.sql.functions.min
而不是
pyspark.sql.functions.count
作为聚合函数。@pault,感谢您的回复,但我尝试使用窗口函数获取最小值,但我的问题是获取最小值产品的地区和国家。
df = spark.read.csv(path,header=True)
w1 = Window.partitionBy(df.product).orderBy(df.value.desc())
df = df.withColumn('min_x',min(df.value).over(w1)).\
        withColumn('region_country',concat_ws('_',first('region'),first('country')))