इवोल्यूशन्स जोड़ना

इंटरमीडिएट Predictive Analytics in Python

Nele Verbiest

Senior Data Scientist @PythonPredictions

इवोल्यूशन्स की आवश्यकता (1)

इंटरमीडिएट Predictive Analytics in Python

इवोल्यूशन्स की आवश्यकता (2)

इंटरमीडिएट Predictive Analytics in Python

इवोल्यूशन्स की आवश्यकता (3)

इंटरमीडिएट Predictive Analytics in Python

इवोल्यूशन्स की आवश्यकता (4)

इंटरमीडिएट Predictive Analytics in Python

इवोल्यूशन्स की आवश्यकता (5)

इंटरमीडिएट Predictive Analytics in Python

बेसटेबल में इवोल्यूशन्स जोड़ना (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)]
इंटरमीडिएट Predictive Analytics in Python

बेसटेबल में इवोल्यूशन्स जोड़ना (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"]
इंटरमीडिएट Predictive Analytics in Python

बेसटेबल में इवोल्यूशन्स जोड़ना (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"]
इंटरमीडिएट Predictive Analytics in Python

बेसटेबल में इवोल्यूशन्स जोड़ना (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
इंटरमीडिएट Predictive Analytics in Python

अभ्यास करते हैं!

इंटरमीडिएट Predictive Analytics in Python

Preparing Video For Download...