開始使用免費開始

快取 DataFrame

你被指派一個需要在 DataFrame 上執行多個分析操作的任務。你已經學到,在重複使用 DataFrame 時使用快取可以提升效能,因此想要實作看看。

你將使用一個新的資料集,內容是航空公司起飛資訊。它可能包含重複資料,需要去重。

DataFrame departures_df 已經定義,但尚未執行任何動作。

本練習屬於課程

使用 PySpark 清理資料

檢視課程

練習說明

  • departures_df DataFrame 的唯一列快取起來。
  • departures_df 執行計數查詢,並記錄此操作花費的時間。
  • 再次計數列數,並觀察在快取後 DataFrame 的時間差異。

動手互動練習

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

start_time = time.time()

# Add caching to the unique rows in departures_df
departures_df = departures_df.____.____

# Count the unique rows in departures_df, noting how long the operation takes
print("Counting %d rows took %f seconds" % (departures_df.____, time.time() - start_time))

# Count the rows again, noting the variance in time of a cached DataFrame
start_time = time.time()
print("Counting %d rows again took %f seconds" % (____, time.time() - start_time))
編輯並執行程式碼