# Python - guided app project average calculation

Profitable apps : user ratings

Looking at the list below, and referencing the code ‘app[5]’ I count 5 from the left to find ratings but this is ‘0.0’, so I do not think this is the ratings for ioS? I have trouble seeing where the ratings come for the genre.

I see that genre_app = app[-5] corresponds to the text genre i.e ‘Games’
but I only see ‘0.0’ for app[5] in this list

[‘389801252’, ‘Instagram’, ‘113954816’, ‘USD’, ‘0.0’, ‘2161558’, ‘1289’, ‘4.5’, ‘4.0’, ‘10.23’, ‘12+’, ‘Photo & Video’, ‘37’, ‘0’, ‘29’, ‘1’]

[‘529479190’, ‘Clash of Clans’, ‘116476928’, ‘USD’, ‘0.0’, ‘2130805’, ‘579’, ‘4.5’, ‘4.5’, ‘9.24.12’, ‘9+’, ‘Games’, ‘38’, ‘5’, ‘18’, ‘1’]

I have trouble understanding the calculation for average games :

``````avg_n_ratings = total / len_genre
``````

If it is taking a count of the number of ratings (not actual) and then dividing by total count of the app, I would have thought the total would be one?

Since every time it comes across a rating it increments by 1 and likewise for every time it comes across a genre in the loop; therefore if there were 3 ratings I assume it could only also result in a find of a count of 3 for the genre, and then it would be 3/3 =1. With these results:

Social Networking : 1
Photo & Video : 1
Games : 1
Music : 1

However this is not the case, it is numbers like these:

Social Networking : 71548.34905660378
Photo & Video : 28441.54375
Games : 22788.6696905016
Music : 57326.530303030304

So there is something I seem to be missing.

``````    genres_ios = freq_table(ios_final, -5)

for genre in genres_ios:
total = 0
len_genre = 0
for app in ios_final:
genre_app = app[-5]
if genre_app == genre:
n_ratings = float(app[5])
total += n_ratings
len_genre += 1
avg_n_ratings = total / len_genre
print(genre, ':', avg_n_ratings)
``````

Hi @jamesberentsen. I’m thinking the difficulty you’re having might have to do with Python’s zero-indexing. We have to remember to start with 0 when counting from the first element, so `app[5]` here is not referring to ‘0.0’ (the price column). I think this will help with the confusion:
The `'rating_count_tot'` column (`app[5]`) gives the number of ratings each app has received. The loop is finding the average of the number of ratings each app has received within the genre. So for example if we had only 3 game apps that have 64800, 98400, and 51200 ratings, then the average number of ratings we have for game apps would be (64900+98400+51200)/3 = 71500.