진화 추가하기

Python 중급 예측 분석

Nele Verbiest

Senior Data Scientist @PythonPredictions

진화의 동기 (1)

Python 중급 예측 분석

진화의 동기 (2)

Python 중급 예측 분석

진화의 동기 (3)

Python 중급 예측 분석

진화의 동기 (4)

Python 중급 예측 분석

진화의 동기 (5)

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)]
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"]
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"]
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
Python 중급 예측 분석

연습해 봅시다!

Python 중급 예측 분석

Preparing Video For Download...