開始使用免費開始

第 1 部分:從 CSV 檔建立 DataFrame

每隔 4 年,全球的足球迷都會迎來「Fifa 世界盃」,而各國也隨之掀起一波風潮。在這個分成 3 個部分的練習中,你將使用 PySpark SQL,針對「FIFA 2018 World Cup Player」資料集進行探索式資料分析(EDA),內容包含 DataFrame 操作、SQL 查詢與視覺化。

在第一部分,你會把 CSV 格式的 FIFA 2018 World Cup Players 資料集(Fifa2018_dataset.csv)載入為 PySpark 的 DataFrame,並用基本的 DataFrame 操作來檢視資料。

別忘了,工作環境中已經提供 SparkSession spark 與變數 file_path

本練習屬於課程

使用 PySpark 的 Big Data 基礎

檢視課程

練習說明

  • file_path(也就是 Fifa2018_dataset.csv 的路徑)建立一個 PySpark DataFrame。
  • 列印該 DataFrame 的綱要(schema)。
  • 顯示前 10 筆觀測值。
  • 這個 DataFrame 總共有多少列?

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Load the Dataframe
fifa_df = spark.____(____, header=True, inferSchema=True)

# Check the schema of columns
fifa_df.____()

# Show the first 10 observations
fifa_df.____(____)

# Print the total number of rows
print("There are {} rows in the fifa_df DataFrame".format(fifa_df.____()))
編輯並執行程式碼