In [ ]:


In [ ]:


In [ ]:

iPython notebook - Daryna analysis - Conversions by website pages

1. Import libraries


In [53]:
%matplotlib inline 

import numpy as np
import scipy as sp
import matplotlib as mpl
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import pandas as pd

pd.set_option('display.width', 500)
pd.set_option('display.max_columns', 100)
pd.set_option('display.notebook_repr_html', True)
import seaborn as sns #sets up styles and gives us more plotting options
  1. Settings

In [54]:
# Time period 24th Jan - 24th April (arbitrary )

# API credentials
# Email address 705762800217-compute@developer.gserviceaccount.com
# Key IDs 948ee8e2a420ef14a5d5a29bd35104fe2f1e6ed4

In [55]:
# open file. It is requested via API explorer using request parameters:

#Account: TMRW Tech Hub
#Property: TMRW
#View: All Web Site Data
#ids: ga:123303369
#start-date: 2017-01-24
#end-date: 2017-04-24

#metrics
#ga:sessions
#ga:sessionsWithEvent

#dimensions
#ga:pagePath

#sort
#-ga:sessionsWithEvent

#filter
#ga:sessions>10

In [56]:
# Open file
# original file exported from GA includes ga:pagePath,ga:sessions,ga:sessionsWithEvent
# Calculate "rate" as "Sessions with event"/"Sessions" for each page.

TMRW_events= pd.read_csv("C:\ProgramData\Anaconda3/tmrw_events.csv")
TMRW_events


Out[56]:
ga:pagePath rate
0 '/ 0.0185
1 '/TMRW_FAQs.php 0.2600
2 '/TMRW_Byte_Cafe.php 0.1055
3 '/TMRW_the_team.php 0.1010
4 '/trainstrikes.php 0.0000
5 '/voteforbyte.php 0.0000

In [57]:
TMRW_events.columns=["page","rate"]
TMRW_events


Out[57]:
page rate
0 '/ 0.0185
1 '/TMRW_FAQs.php 0.2600
2 '/TMRW_Byte_Cafe.php 0.1055
3 '/TMRW_the_team.php 0.1010
4 '/trainstrikes.php 0.0000
5 '/voteforbyte.php 0.0000

In [58]:
TMRW_events_filter = TMRW_events[TMRW_events.rate > 0]
TMRW_events_filter


Out[58]:
page rate
0 '/ 0.0185
1 '/TMRW_FAQs.php 0.2600
2 '/TMRW_Byte_Cafe.php 0.1055
3 '/TMRW_the_team.php 0.1010

In [59]:
TMRW_events_filter.describe()


Out[59]:
rate
count 4.000000
mean 0.121250
std 0.100776
min 0.018500
25% 0.080375
50% 0.103250
75% 0.144125
max 0.260000

In [64]:
#import numpy as np
from bokeh.io import output_notebook
from bokeh.charts import Bar, show

output_notebook()
p = Bar(TMRW_events_filter, 'page', values='rate', title="Events per page")
show(p)


Loading BokehJS ...

In [65]:
TMRW_events_data = TMRW_events_filter.groupby(['page']).mean()
TMRW_events_data


Out[65]:
rate
page
'/ 0.0185
'/TMRW_Byte_Cafe.php 0.1055
'/TMRW_FAQs.php 0.2600
'/TMRW_the_team.php 0.1010

In [67]:
selected=TMRW_events_data.loc[:,"rate"]
selected


Out[67]:
page
'/                      0.0185
'/TMRW_Byte_Cafe.php    0.1055
'/TMRW_FAQs.php         0.2600
'/TMRW_the_team.php     0.1010
Name: rate, dtype: float64

In [68]:
labels = selected.index
sizes = TMRW_events_filter['rate']
colors = ['green','yellow', 'red', 'lightskyblue']
explode = (0, 0, 0,0)
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
        autopct='%1.1f%%', shadow=False, startangle=90)
plt.legend(patches, labels, loc="best")
plt.axis('equal')
plt.title('Conversions by pages                                    ')
plt.tight_layout()
plt.show()



In [ ]:


In [ ]: