In [10]:
%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 [11]:
# Time period 1st Jan - 30th April (arbitrary )
# API credentials
# Email address 705762800217-compute@developer.gserviceaccount.com
# Key IDs 948ee8e2a420ef14a5d5a29bd35104fe2f1e6ed4
In [13]:
# open file. It is requested via API explorer using request parameters:
#Account: Skein.co
#Property: Skein.co
#View: Skein.co - Report
#ids: ga:93735856
#start-date: 2017-02-01
#end-date: 2017-04-30
#metrics
#ga:sessions
#ga:goal1Completions
#ga:bounceRate
#dimensions
#ga:deviceCategory
In [14]:
# Open file
input_mob= pd.read_csv('skein_data/Skein_mob.csv')
# rename columns
input_mob.columns=['Device','Sessions','Bounce Rate','Conversions']
# group by device
input_mob = input_mob.set_index('Device')
input_mob
Out[14]:
In [15]:
input_mob['CR'] = input_mob.Conversions / input_mob.Sessions * 100
input_mob
Out[15]:
In [16]:
mobile_Sessions = input_mob.loc['mobile','Sessions']
desktop_CR = input_mob.loc['desktop','CR']
mobile_Conversions = input_mob.loc['mobile','Conversions']
mobile_CR = input_mob.loc['mobile','CR']
conv_increase = "%.0f" % (mobile_Sessions * desktop_CR - mobile_Conversions)
conv_increase = int(conv_increase)
#mobileSessions
#desktopCR
#mobileConversions
mobile_CR
Out[16]:
In [17]:
#if mobile CR is greater, equel or less by more than 20% result is failed
dif = mobile_CR / desktop_CR
if dif > 0.8:
result = False
else:
result = True
result
Out[17]:
In [18]:
output_chart_mob = input_mob.loc['mobile',['Sessions','Conversions']]
output_chart_mob.plot.barh(stacked=True)
labels = output_chart_mob.index
sizes = output_chart_mob
# colours are taken from http://tools.medialab.sciences-po.fr/iwanthue/
colors = ['#b94663','#6fac5d', '#677ad1']
explode = (0, 0, 0)
plt.xlabel('Visits')
plt.title('Only %s ' % ("%.2f" % (mobile_CR*100) +'% of all mobile visits end up completing a conversion' ))
#need to specify analytics time perdiod
print ("Have %s more conversions per month by optmising mobile UX" % conv_increase)
plt.show()
In [6]:
import json
%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
In [10]:
with open('files/TMRW_mob.json') as file: #открываем файл на чтение
input_mob = json.load(file) #загружаем из файла данные в словарь data
input_mob
Out[10]:
In [18]:
columns = input_mob['columnHeaders']
columns
Out[18]:
In [21]:
rows = input_mob['rows']
rows
Out[21]:
In [ ]: