Google Analytics Exploration -1
Insert the link to your Google Sheet
import pandas as pd
import re
# This function will convert the url to a download link
def convert_gsheets_url(u):
try:
worksheet_id = u.split('#gid=')[1]
except:
# Couldn't get worksheet id. Ignore it
worksheet_id = None
u = re.findall('https://docs.google.com/spreadsheets/d/.*?/',u)[0]
u += 'export'
u += '?format=csv'
if worksheet_id:
u += '&gid={}'.format(worksheet_id)
return u
sample_url = 'https://docs.google.com/spreadsheets/d/1ih4V4CumuIl5ZynobsazNzGiaPrE2V2Dpt13FI22XNU/edit'
try:
url = convert_gsheets_url(URL)
df = pd.read_csv(url)
print('Read successfully')
except:
print(f"Could not read any data from the URL you provided.\nReading from {sample_url} instead.")
url = convert_gsheets_url(sample_url)
df = pd.read_csv(url)
Exploring the data types
df.info()
The top 10 pages on the website: An overview
Visualization of top 10 pages by "page views"
General Stats for the top 10 pages
df.describe()
Identifying the best performing pages on the website
df = df.astype({"Bounce Rate": str})
df['Bounce Rate'] = df['Bounce Rate'].str.rstrip('%').astype('float')
df.info()
best_performing = df[(df["Page Views"]>= 20) & (df["Bounce Rate"]<= 0.9)]
print(best_performing)
best_performing