เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Aggregating II

To get you familiar with more of the built in aggregation methods, here's a few more exercises involving the flights table!

Remember, a SparkSession called spark is already in your workspace, along with the Spark DataFrame flights.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Foundations of PySpark

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Use the .avg() method to get the average air time of Delta Airlines flights (where the carrier column has the value "DL") that left SEA. The place of departure is stored in the column origin. show() the result.
  • Use the .sum() method to get the total number of hours all planes in this dataset spent in the air by creating a column called duration_hrs from the column air_time. show() the result.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Average duration of Delta flights
flights.filter(____.____ == "____").filter(____.____ == "____").groupBy().avg("____").show()

# Total hours in the air
flights.withColumn("____", flights.air_time/60).groupBy().sum("____").show()
แก้ไขและรันโค้ด