Maximum value last year
Next, you would like to add the maximum amount that a donor donated in 2017, but before May 1st, 2017 to the basetable. You have a few objects available to you: basetable
contains the donor IDs of the population, and gifts
contains gifts made by donors over time. For each donor in the population, add the maximum amount that this donor donated in 2017 to 'basetable`.
Cet exercice fait partie du cours
Intermediate Predictive Analytics in Python
Instructions
- Fill out the start and end date of the period over which you want to take the maximum.
- Select gifts made in 2017 using these start and end dates in the dataframe
gifts_2017
. - Create a pandas dataframe that has the maximum amount for each donor in
gifts_2017
. - Add this maximum amount to the
basetable
.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Start and end date of the aggregation period
start_date = datetime.date(____, ____, ____)
end_date = datetime.date(____, ____, ____)
# Select gifts made in 2017
gifts_2017 = gifts[(gifts["____"] >= ____) & (gifts["____"] < ____)]
# Maximum gift per donor in 2017
gifts_2017_bydonor = gifts_2017.groupby(["____"])["____"].____().reset_index()
gifts_2017_bydonor.columns = ["donor_ID", "max_amount"]
# Add maximum amount to the basetable
basetable = pd.merge(____, ____)