Most Popular Apps by Genre on Google Play Problem in Nested Loop

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

My Code:

genre_type_android = categorize(android_eng_free,1)


for genre in genre_type_android:
    total = 0 
    len_genre = 0
    for row in android_eng_free:
        genre_app = row[1]
        n_installs = row[5]
        n_installs = n_installs.replace(',','')
        n_installs = n_installs.replace('+','')
        n_installs = float(n_installs)
        if genre == genre_app:
            total += n_installs
            len_genre += 1          
    avg_n_installs = n_installs / len_genre 
    print(genre, ';', avg_n_installs)

What I expected to happen:

ART_AND_DESIGN : 1986335.0877192982
AUTO_AND_VEHICLES : 647317.8170731707
BEAUTY : 513151.88679245283
BOOKS_AND_REFERENCE : 8767811.894736841
BUSINESS : 1712290.1474201474
COMICS : 817657.2727272727
COMMUNICATION : 38456119.167247385
DATING : 854028.8303030303
EDUCATION : 1833495.145631068
ENTERTAINMENT : 11640705.88235294
EVENTS : 253542.22222222222
FINANCE : 1387692.475609756
FOOD_AND_DRINK : 1924897.7363636363
HEALTH_AND_FITNESS : 4188821.9853479853
HOUSE_AND_HOME : 1331540.5616438356
LIBRARIES_AND_DEMO : 638503.734939759
LIFESTYLE : 1437816.2687861272
GAME : 15588015.603248259
FAMILY : 3695641.8198090694
MEDICAL : 120550.61980830671
SOCIAL : 23253652.127118643
SHOPPING : 7036877.311557789
PHOTOGRAPHY : 17840110.40229885
SPORTS : 3638640.1428571427
TRAVEL_AND_LOCAL : 13984077.710144928
TOOLS : 10801391.298666667
PERSONALIZATION : 5201482.6122448975
PRODUCTIVITY : 16787331.344927534
PARENTING : 542603.6206896552
WEATHER : 5074486.197183099
VIDEO_PLAYERS : 24727872.452830188
NEWS_AND_MAGAZINES : 9549178.467741935
MAPS_AND_NAVIGATION : 4056941.7741935486

What actually happened:

ART_AND_DESIGN ; 175438.59649122806
AUTO_AND_VEHICLES ; 121951.21951219512
BEAUTY ; 188679.24528301886
BOOKS_AND_REFERENCE ; 52631.57894736842
BUSINESS ; 24570.02457002457
COMICS ; 181818.18181818182
COMMUNICATION ; 34843.20557491289
DATING ; 60606.06060606061
EDUCATION ; 97087.3786407767
ENTERTAINMENT ; 117647.05882352941
EVENTS ; 158730.15873015873
FINANCE ; 30487.80487804878
FOOD_AND_DRINK ; 90909.09090909091
HEALTH_AND_FITNESS ; 36630.03663003663
HOUSE_AND_HOME ; 136986.301369863
LIBRARIES_AND_DEMO ; 120481.92771084337
LIFESTYLE ; 28901.73410404624
GAME ; 11600.92807424594
FAMILY ; 5970.149253731343
MEDICAL ; 31948.88178913738
SOCIAL ; 42372.8813559322
SHOPPING ; 50251.25628140703
PHOTOGRAPHY ; 38314.17624521073
SPORTS ; 33222.591362126244
TRAVEL_AND_LOCAL ; 48309.178743961354
TOOLS ; 13333.333333333334
PERSONALIZATION ; 34013.60544217687
PRODUCTIVITY ; 28985.507246376812
PARENTING ; 172413.7931034483
WEATHER ; 140845.0704225352
VIDEO_PLAYERS ; 62893.08176100629
NEWS_AND_MAGAZINES ; 40322.58064516129
MAPS_AND_NAVIGATION ; 80645.16129032258

I don’t get what’s the difference between my code and solution code on GitHub(pasted below). I know my framing is difference but I am having hard time understanding where I went wrong. Are there any videos on YouTube or somewhere where I can work on this topic. Also when I run git hub’s code I get the correct answer. PLEASE HELP!!!

genre_type_android = categorize(android_eng_free,1)


for category in genre_type_android:
    total = 0
    len_category = 0
    for app in android_eng_free:
        category_app = app[1]
        if category_app == category:            
            n_installs = app[5]
            n_installs = n_installs.replace(',', '')
            n_installs = n_installs.replace('+', '')
            total += float(n_installs)
            len_category += 1
    avg_n_installs = total / len_category
    print(category, ':', avg_n_installs)

The average number of installs is based on the total number of installs and not on n_installs.

1 Like

Okay !!! Well now I feel just silly asking it. Anyways Thanks… I think my mind is just tired missing obvious things LOL :stuck_out_tongue: