將 CSV 載入為 DataFrame
在上一個練習中,你已經看過如何從 RDD 建立 DataFrame。一般來說,從 CSV 檔載入資料是建立 DataFrame 最常見的方法。在本練習中,你要從已提供為 file_path 的 people.csv 檔建立一個 PySpark DataFrame,並確認建立出的物件確實是 PySpark 的 DataFrame。
請記住,你的工作區中已經有 SparkSession spark,以及變數 file_path(指向 people.csv 檔案的路徑)。
本練習屬於課程
使用 PySpark 的 Big Data 基礎
練習說明
- 由
file_path變數(people.csv檔案的路徑)建立一個 DataFrame。 - 確認輸出為 PySpark 的 DataFrame。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create an DataFrame from file_path
people_df = spark.____(file_path, header=True, inferSchema=True)
# Check the type of people_df
print("The type of people_df is", ____(people_df))