pyspark的窗函数fn.avg()只输出同一数据(pyspark's window fu

2019-10-28 09:14发布

这里是我的代码:

import pandas as pd
from pyspark.sql import SQLContext
import pyspark.sql.functions as fn
from pyspark.sql.functions import isnan, isnull
from pyspark.sql.functions import lit
from pyspark.sql.window import Window

spark= SparkSession.builder.appName(" ").getOrCreate()
file = "D:\project\HistoryData.csv"
lines = pd.read_csv(file)
spark_df=spark.createDataFrame(cc,['id','time','average','max','min'])

temp = Window.partitionBy("time").orderBy("id").rowsBetween(-1, 1)

df = spark_df.withColumn("movingAvg",fn.avg("average").over(temp))

df.show()

但它输出这样的:

它的输出相同的数据,有些数据是消失。

文章来源: pyspark's window functions fn.avg() only output same data