检测季节性
假设您要预测某位潜在捐赠者是否会在下个月捐赠。作为预测变量,您想包含上个月的平均捐赠、最大捐赠和最小捐赠等变量。
给定一个包含 2017 年所有捐赠记录的 pandas 数据框 gifts。请检查捐赠是否存在季节性,以判断在构建基表时是否需要考虑季节性。
本练习是课程的一部分
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)