Adding evolutions

Python ile Orta Düzey Öngörüsel Analitik

Nele Verbiest

Senior Data Scientist @PythonPredictions

Motivation for evolutions (1)

Python ile Orta Düzey Öngörüsel Analitik

Motivation for evolutions (2)

Python ile Orta Düzey Öngörüsel Analitik

Motivation for evolutions (3)

Python ile Orta Düzey Öngörüsel Analitik

Motivation for evolutions (4)

Python ile Orta Düzey Öngörüsel Analitik

Motivation for evolutions (5)

Python ile Orta Düzey Öngörüsel Analitik

Adding evolutions to the basetable (1)

# Reference dates
start_2017 = datetime.date(2017,1,1)
start_2016 = datetime.date(2016,1,1)
start_2015 = datetime.date(2015,1,1)
# Gifts last month and last year
gifts_2016 = gifts[
   (gifts["date"]<start_2017) 
    & (gifts["date"]>=start_2016)]

gifts_2015_and_2016 = gifts[
   (gifts["date"]<start_2017) 
    & (gifts["date"]>=start_2015)]
Python ile Orta Düzey Öngörüsel Analitik

Adding evolutions to the basetable (2)

# Number of gifts in these periods per donor
number_gifts_2016 = gifts_2016.groupby("id")["amount"].size().reset_index()
number_gifts_2016.columns = ["donor_ID", "number_gifts_2016"]

number_gifts_2015_and_2016 = gifts_2015_and_2016 .groupby("id")["amount"].size().reset_index() number_gifts_2015_and_2016.columns = ["donor_ID", "number_gifts_2015_and_2016"]
Python ile Orta Düzey Öngörüsel Analitik

Adding evolutions to the basetable (3)

# Add these numbers to the basetable
basetable = pd.merge(basetable, 
                     number_gifts_2016, 
                     on="donor_ID",
                     how = "left")
basetable = pd.merge(basetable, 
                     number_gifts_2015_and_2016, 
                     on="donor_ID",
                     how = "left")

# Calculate ratio of last month's and last year's average basetable["ratio_2015_to_2015_and_2016"] = basetable["number_gifts_2016"] / basetable["number_gifts_2015_and_2016"]
Python ile Orta Düzey Öngörüsel Analitik

Adding evolutions to the basetable (4)

print(basetable.head())
donor_id number_gifts_2016 number_gifts_2015_and_2016 ratio_2015_to_2015_and_2016
1        Na                5                          Na
2        9                 12                         0.75
3        3                 6                          0.5
Python ile Orta Düzey Öngörüsel Analitik

Let's practice!

Python ile Orta Düzey Öngörüsel Analitik

Preparing Video For Download...