BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

Experimental Snippet Shows Percentage Value Printing Wrong The 2nd Time As Opposed To The First Time, Why?

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

My Code:

ios = list(reader(open('AppleStore.csv')))
blank1={}
for app in ios:
    if app[11] not in blank1:
        blank1[app[11]] = 1
    else:
        blank1[app[11]] += 1

print('Games:',blank1['Games']/sum(blank1.values())*100)        
print(sum(blank1.values()))
for row in blank1:
    percentage1 = blank1[row]/sum(blank1.values())*100
    blank1[row] = percentage1
print(blank1)

What I expected to happen: Percentage to be 53.65379 approx

What actually happened: look at screenshot

N/A

what event in the operational chronology is changing the output values on 2nd time
(please don’t say stuff like "your output is wrong because the dictionary has ‘prime genre’ as a key too and etc etc. plz focus and help me focus too, the aim of the question is to know the mechanism/chronology of operations in this and not to master the cosmetics. (as i specified in question “EXPERIMENTAL” as the first word of my question, shows my purpose of doing this) so steer clear if u cant be content with it.)

PLEASE FEEL FREE TO ASK FOR MORE DETAILS if needed, let me know what more info you would need to help me figure out the answer to this situation. ty.

Has any1 come across this situation?

Here is your culprit:

    blank1[row] = percentage1

Check it out:

for row in blank1:
    percentage1 = blank1[row]/sum(blank1.values())*100
    text = 'Total after {genre} is: \t {total}'
    print(text.format(genre=str(row), total=sum(blank1.values())).expandtabs(18))
    blank1[row] = percentage1

Output:
Total after prime_genre is:          7198
Total after Social Networking is:    7197.013892747986
Total after Photo & Video is:        7032.334299551261
Total after Games is:                6688.297089787531
Total after Music is:                2884.0397400937945
Total after Reference is:            2750.8246949639206
Total after Health & Fitness is:     2689.1512699767586
Total after Weather is:              2515.844831696756
Total after Utilities is:            2446.706693409883
Total after Travel is:               2208.8427673687265
Total after Shopping is:             2131.509845949267
Total after News is:                 2015.23348828814
Total after Navigation is:           1943.955141408529
Total after Lifestyle is:            1900.3214511561227
Total after Entertainment is:        1763.8991164986041
Total after Food & Drink is:         1259.229649293586
Total after Sports is:               1201.2327081109622
Total after Book is:                 1096.722959186399
Total after Finance is:              994.9352009437055
Total after Education is:            901.3881429947411
Total after Productivity is:         498.64396270132926
Total after Business is:             356.34077511949465
Total after Catalogs is:             315.3366992404111
Total after Medical is:              308.507912747779
Expand this text if the above doesn't make sense

Because you’re using sum(blank1.values()) to calculate the percentage, you will want to avoid updating blank1 thereby inadvertently destroying the value of sum(blank1.values())with each pass of your for loop.

Oh yes, thats right i’ve been assigning percentage variable to Blank1{} again in the loop and its updating .
unbelievable how i missed to see that.
tyvm. Appreciate it.