【发布时间】:2019-07-19 17:40:55
【问题描述】:
我有一个包含国家、地区、价值、产品的数据集。需要将 min_x 和 region-country 与 min-value 作为单独的列
数据集
cust Country Region value product
100 france europe 1 x
101 france europe 2 x
102 poland europe 3 x
103 poland europe 3 y
104 france europe 4 y
105 france europe 5 y
我希望所有客户中每种产品的最低价值。为此,我按产品分组。
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 的区域国家的列。加入时无法获取国家和地区的值。
【问题讨论】:
-
与我链接的帖子的概念相同,但使用
pyspark.sql.functions.min而不是pyspark.sql.functions.count作为聚合函数。 -
@pault,感谢您的回复,但是当我尝试使用窗口函数获取最小值时,我的问题是获取最小值产品的区域国家/地区。
标签: pyspark