teceai

Untitled

Apr 9th, 2021
1,070
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pyspark.sql import SparkSession
  2.  
  3. APP_NAME = "DataFrames"
  4. SPARK_URL = "local[*]"
  5.  
  6. spark = SparkSession.builder.appName(APP_NAME) \
  7.         .config('spark.ui.showConsoleProgress', 'false') \
  8.         .getOrCreate()
  9.  
  10. taxi = spark.read.load('/datasets/pickups_terminal_5.csv',
  11.                        format='csv', header='true', inferSchema='true')
  12.  
  13. taxi = taxi.fillna(0)
  14.  
  15. taxi.registerTempTable("taxi")
  16.  
  17. print(spark.sql('SELECT hour, AVG(pickups) FROM taxi GROUP BY hour ORDER BY AVG(pickups) DESC LIMIT 10').show())
RAW Paste Data