In [ ]:
In [ ]:
In [ ]:
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
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]:
In [57]:
TMRW_events.columns=["page","rate"]
TMRW_events
Out[57]:
In [58]:
TMRW_events_filter = TMRW_events[TMRW_events.rate > 0]
TMRW_events_filter
Out[58]:
In [59]:
TMRW_events_filter.describe()
Out[59]:
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)
In [65]:
TMRW_events_data = TMRW_events_filter.groupby(['page']).mean()
TMRW_events_data
Out[65]:
In [67]:
selected=TMRW_events_data.loc[:,"rate"]
selected
Out[67]:
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 [ ]: