開始使用免費開始

偵測季節性

假設你想預測某位潛在捐款人在下個月是否會捐款。作為預測變數,你想納入上個月的平均捐款、最高捐款與最低捐款等變數。 給定一個 pandas DataFrame gifts,其中包含 2017 年的所有捐款紀錄。請檢查捐款是否具有季節性,以判斷在建立 base table 時是否需要考量季節性。

本練習屬於課程

Python 中級預測分析

檢視課程

練習說明

  • 針對每個「month」,計算所有捐款人的平均捐款金額。
  • 針對每個「month」,計算所有捐款人的捐款次數。
  • 針對每個「month」,計算所有捐款金額的中位數。

動手互動練習

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

# Calculate the mean amount donated per month
mean_per_month = gifts.____("month")["amount"].____().reset_index()
print(mean_per_month)

# Calculate the number of donations per month 
number_per_month = ____.____("month").____().reset_index()
print(number_per_month)

# Calculate the median amount donated per month 
median_per_month = ____.____("____")["____"].____().reset_index()
print(median_per_month)
編輯並執行程式碼