pyspark's window functions fn.avg() only outpu

2019-08-26 15:53发布

Here is my code:

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

But it output this: enter image description here

It output the same data,and some data is disappear.

0条回答
登录 后发表回答