Guided Project App Profile Recommendation------Most popular App store app

Screen Link:
https://app.dataquest.io/c/112/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/12/most-popular-apps-by-genre-on-the-app-store

My Code:

My code:
prime_genre=freq_table(free_ios_apps,11)

total=0
len_genre=0
for each_row in free_ios_apps:
    genre=each_row[11]
    
    for genre in prime_genre:
        if genre in prime_genre:
            app=each_row[1]
            rating=float(each_row[5])
            len_genre+=1
            total+=rating

    avg_app_genre=total/len_genre
      
    print(genre,':',avg_app_genre)

solution Code
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 I expected to happen:
I expected to get avg rating per genre based on apps ratings

What actually happened:

Medical : 798624.0606060605
Medical : 786707.7352941176
Medical : 775413.2571428572
Medical : 764610.6944444445
Medical : 754049.7837837838
Medical : 744044.1315789474
Medical : 734543.4871794871
Medical : 725439.15
Medical : 716521.9024390244
Medical : 707891.8095238095
Medical : 699602.8372093023
Medical : 691544.7272727273
Medical : 683798.6
Medical : 676200.6521739131
Medical : 668771.3829787234
Medical : 661586.6666666666
Medical : 654387.8367346938
Medical : 647377.2
Medical : 640589.0588235294
Medical : 633947.1730769231
Medical : 627530.3773584906
Medical : 621339.5925925926
Medical : 615347.7272727273
Medical : 609555.7321428572
Medical : 603907.1929824562
Medical : 598444.9137931034
Medical : 593016.4576271187
Medical : 587753.9833333333
Medical : 582618.6885245901
Medical : 577534.4193548387
Medical : 572604.0476190476
Medical : 567754.625
Medical : 563034.7846153846
Medical : 558422.5
Medical : 553933.0149253731
Medical : 549567.8235294118
Medical : 545276.231884058
Medical : 541087.6571428571
Medical : 536956.9718309859
Medical : 532859.3611111111
Medical : 528759.904109589
Medical : 524766.7972972973
Medical : 520875.7733333333
Medical : 517052.2631578947
Medical : 513244.896103896

I want to better understand why changing for loops had such a drastic change in result. As far as I can see placement of for loops in my code is the issue. Can someone explain in a little more details