開始使用免費開始

檔案匯入效能

你收到一大批要匯入到 Spark DataFrame 的資料。你想把檔案分割後,測試匯入速度的差異。

你手上有兩種檔案可用:departures_full.txt.gzdepartures_xxx.txt.gz,其中 xxx 介於 000013。相同的列數平均分散在各個檔案中。

本練習屬於課程

使用 PySpark 清理資料

檢視課程

練習說明

  • 分別將 departures_full.txt.gz 檔案與 departures_xxx.txt.gz 檔案匯入成不同的 DataFrame。
  • 對每個 DataFrame 執行 count,並比較執行時間。

動手互動練習

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

# Import the full and split files into DataFrames
full_df = spark.read.csv('____')
split_df = ____(____)

# Print the count and run time for each DataFrame
start_time_a = time.time()
print("Total rows in full DataFrame:\t%d" % ____)
print("Time to run: %f" % (time.time() - start_time_a))

start_time_b = time.time()
print("Total rows in split DataFrame:\t%d" % ____)
print("Time to run: %f" % (time.time() - start_time_b))
編輯並執行程式碼