repl.it
@technicallyprod/

Google Analytics average age

Python

Calculates the average age of your Google Analytics user (with a lot of caveats). See https://www.technicallyproduct.co.uk/analytics/calculating-the-mean-average-age-of-your-users-from-google-analytics-demographic-data-using-python/ for a full explanation

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
agebrackets=["18-24","25-34", "35-44","45-54","55-64","65+"]
means=[21,29.5,39.5,49.5,59.5,70]
results=[]
totalage=0

print("Welcome to my average age calculator for Google Analytics data.\n\n"
      "In your Google Analytics view, go to Audience > Demographics > Age\n\n"
      "Then enter the figures as prompted below.\n\n")

for i in range(len(agebrackets)):
    print("How many USERS are ",(agebrackets[i]),"?",sep="")
    tempinput=(input())
    tempinput=tempinput.replace(',','')
    results.append(int(tempinput))

for i in range(len(agebrackets)):
    totalage+=(means[i]*results[i])

meanage=totalage/(sum(results))
print("The mean average age of your users is: {:.1f} years old".format(meanage))
Fetching token
?