-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAB test Pandas
43 lines (32 loc) · 1.68 KB
/
AB test Pandas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import codecademylib
import pandas as pd
ad_clicks = pd.read_csv('ad_clicks.csv')
print(ad_clicks.head())
number_each= ad_clicks.groupby('utm_source').user_id.count().reset_index()
print(number_each)
#ad_clicks['is_click']=ad_clicks.ad_click_timestamp.isnull()
#ad_clicks['is_click']=ad_clicks.apply(lambda x: 'not visit' if pd.isnull(x['ad_click_timestamp']) else 'visit',axis=1)
ad_clicks['is_click']=ad_clicks.ad_click_timestamp.apply(lambda x: 'not visit' if pd.isnull(x) else 'visit')
print(ad_clicks)
clicks_by_source=ad_clicks.groupby(['utm_source','is_click']).user_id.count().reset_index()
#clicks_by_source = ad_clicks.groupby(['utm_source','is_click']).user_id.count().reset_index()
print(clicks_by_source)
clicks_pivot=clicks_by_source.pivot(columns='is_click',index='utm_source',values='user_id').reset_index()
print(clicks_pivot)
clicks_pivot['percent_clicked']=clicks_pivot['visit']/(clicks_pivot['not visit']+clicks_pivot['visit'])*100
print(clicks_pivot)
ab= ad_clicks.groupby('experimental_group').user_id.count().reset_index()
print(ab)
click_ab=ad_clicks.groupby(['experimental_group','is_click']).user_id.count().reset_index()
print(click_ab)
a_clicks=ad_clicks[ad_clicks.experimental_group=='A'].reset_index(drop=True)
print(a_clicks)
print(type(a_clicks))
b_clicks=ad_clicks[ad_clicks.experimental_group=='B'].reset_index(drop=True)
print(b_clicks)
visit_a=a_clicks.groupby(['day','is_click']).user_id.count().reset_index()
print(visit_a)
visit_a_pivot=visit_a.pivot(columns='is_click',index='day',values='user_id').reset_index()
print(visit_a_pivot)
visit_a_pivot['percent_visit']=visit_a_pivot['visit']/(visit_a_pivot['not visit']+visit_a_pivot['visit'])*100
print(visit_a_pivot)