pyspark的DataFrame的groupBy方法实践

csv内容:

pyspark的DataFrame的groupBy方法实践_第1张图片

 

# python3
# -*- coding:utf-8 -*-
# @Time: 9/2/19 12:03 PM
# @Author: Damon
# @Software: PyCharm

from __future__ import print_function
from pyspark import SparkConf,SparkContext
from pyspark.sql import SparkSession

#conf=SparkConf().setAppName("TestAPP").setMaster("local")
#sc=SparkContext(conf=conf)
spark=SparkSession.builder.appName("TestApp").getOrCreate()
#sc.setLogLevel("ERROR")
inputFile="file:///home/hadoop/PycharmProjects/WordCount/data/FACE_TRACE.csv"
#rdd=sc.textFile(inputFile)
df=spark.read.csv(inputFile,header=True)
df1=df.select(df.FACE_CARD_ID,df.TIMESTAMP,df.LNG,df.LAT).groupby(df.TIMESTAMP,df.LNG,df.LAT).count()

#df2=df1.groupBy(df.TIMESTAMP,df.LNG,df.LAT).count()
df1.printSchema()
df1.createOrReplaceTempView("test")

print(df1.filter("count==2").show())

#print(rdd.map(lambda x:x.split(',')[1]).collect())

 

运行结果:

pyspark的DataFrame的groupBy方法实践_第2张图片

 

你可能感兴趣的:(Spark)