पिछले महीने और पिछले साल के औसत का अनुपात
basetable में जोड़ने के लिए एक उपयोगी वैरिएबल है: दानकर्ता ने पिछले महीने जितना औसतन दान किया, उसकी तुलना में पिछले साल का औसत दान. इस अभ्यास में, आप सीखेंगे कि यह वैरिएबल basetable में कैसे जोड़ना है. दानकर्ताओं द्वारा पिछले महीने किए गए दान gifts_last_month में पहले से चुने गए हैं और पिछले साल किए गए दान gifts_last_year में चुने गए हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
इंटरमीडिएट Predictive Analytics in Python
अभ्यास निर्देश
gifts_last_monthमें प्रत्येक दानकर्ता के लिए पिछले महीने का औसत दान निकालिए.gifts_last_yearमें प्रत्येक दानकर्ता के लिए पिछले साल का औसत दान निकालिए.- पिछले महीने का औसत दान और पिछले साल का औसत दान basetable में जोड़िए.
- basetable में पिछले महीने और पिछले साल के औसत दान का अनुपात निकालिए.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Average gift last month for each donor
average_gift_last_month = gifts_last_month.____("____")["____"].____().reset_index()
average_gift_last_month.columns = ["donor_ID", "mean_gift_last_month"]
# Average gift last year for each donor
average_gift_last_year = ____
average_gift_last_year.columns = ["donor_ID", "mean_gift_last_year"]
# Add average gift last month and year to basetable
basetable = pd.merge(____, ____, on="____", how="____")
basetable = pd.merge(____, ____, on="____", how="____")
# Calculate ratio of last month's and last year's average
basetable["ratio_month_year"] = basetable["____"] / basetable["____"]
print(basetable.head())