Hello!
I figured it would be practical to create a more general function to find sum of user ratings per column index. In the exercise, we’re asked to do it directly for the prime genres column [-5] for the ios dataset.
Here is what i tried:
def ratings_per_index(dataset, index):
dataset_freq = freq_table(dataset, index)
for genre in dataset_freq:
total = 0
len_genre = 0
for app in dataset:
genre_app = app[index]
if genre_app == genre:
n_ratings = float(app[5])
total += n_ratings
len_genre += 1
avg_n_ratings = total / len_genre
Then, i tried using the function:
print(ratings_per_index(ios_final,-5))
What i expected was the same answer we’d get without the function:
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)
What actually happened was that i got the result ‘’ None’’.
What am i doing wrong? Help is welcome!!