Available data
Assume that you want to construct a model that predicts whether someone will donate in a certain year. The timeline to construct the basetable has 2017 as target period, this means that the target is based on donations made in 2017, and that the predictive variables are based on donations made before 2017.
All donations are given in a pandas dataframe gifts
with three columns: the donor id
, the donation date
and the amount
donated. In this exercise you will learn to construct a new pandas dataframe that excludes donations made in 2017 or later.
This exercise is part of the course
Intermediate Predictive Analytics in Python
Exercise instructions
- Enter the start date of the target period.
- Construct a pandas dataframe
gifts_before_2017
that only contains gifts made before 2017 (exclusive). - Count the donations in
gifts_before_2017
and print it to the console.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Start of the target is January 1st 2017
start_target = datetime(year=____, month=____, day=____)
# Select gifts made before start_target
gifts_before_2017 = gifts[____[____] < ____]
# Print the number of donations in gifts_before_2017
print(____(____))