【发布时间】:2019-12-03 12:46:50
【问题描述】:
如果我有如下的数据框;
ProductId StoreId Prediction Index
24524 20 3 19
24524 20 5 20
24524 20 1 21
24524 20 2 22
24524 20 3 23
24524 20 1 24
24524 20 3 25
24524 20 4 26
24524 20 5 27
24524 20 6 28
24524 20 1 29
37654 23 8 9
37654 23 3 10
37654 23 4 11
37654 23 5 12
37654 23 6 13
37654 23 7 14
37654 23 8 15
37654 23 4 16
37654 23 2 17
37654 23 4 18
37654 23 3 19
37654 23 7 20
37654 23 7 21
37654 23 3 22
37654 23 2 23
37654 23 3 24
我想根据每个产品和商店对最后 7 个索引进行平均。
ProductId StoreId Prediction(Average)
24524 20 3.28 #(This average is include Index 23, 24, 25, 26, 27, 28 and 29)
37654 23 4.14 #(This average is include Index 18, 19, 20, 21, 22, 23 and 24)
groupby应该怎么做?
df.groupBy(["ProductId","StoreId"]).agg({'Prediction':'avg'}))
你能帮我解决这个问题吗?
【问题讨论】:
标签: pyspark apache-spark-sql pyspark-sql