Přidávání evolucí

Intermediate Predictive Analytics in Python

Nele Verbiest

Senior Data Scientist @PythonPredictions

Motivace pro evoluce (1)

Intermediate Predictive Analytics in Python

Motivace pro evoluce (2)

Intermediate Predictive Analytics in Python

Motivace pro evoluce (3)

Intermediate Predictive Analytics in Python

Motivace pro evoluce (4)

Intermediate Predictive Analytics in Python

Motivace pro evoluce (5)

Intermediate Predictive Analytics in Python

Přidávání evolucí do základní tabulky (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)]
Intermediate Predictive Analytics in Python

Přidávání evolucí do základní tabulky (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"]
Intermediate Predictive Analytics in Python

Přidávání evolucí do základní tabulky (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"]
Intermediate Predictive Analytics in Python

Přidávání evolucí do základní tabulky (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
Intermediate Predictive Analytics in Python

Pojďme si procvičit!

Intermediate Predictive Analytics in Python

Preparing Video For Download...