Dictionaries and Frequence Tables: Final Mission

Screen Link:
https://app.dataquest.io/m/314/dictionaries-and-frequency-tables/13/filtering-for-the-intervals

My Code:

ratings_count = []
for row in apps_data[1:]:
    ratings_count_tot = int(row[5])
    ratings_count.append(ratings_count_tot)
    
min_ratings_count = min(ratings_count)
max_ratings_count = max(ratings_count)

print(min_ratings_count)
print(max_ratings_count)

ratings_intervals = {'0-600000' : 0, '600001-1200000' : 0, '1200001-1800000' : 0, '1800001-2400000' : 0, 
                    '2400001-3000000' : 0, '3000000+' : 0}
for row in apps_data[1:]:
    
    if ratings_count_tot <= 600000:
        ratings_intervals['0-600000'] += 1
    
    elif 600000 < ratings_count_tot <= 1200000:
        ratings_intervals['600001-1200000'] += 1
    
    elif 1200000 < ratings_intervals <= 1800000:
        ratings_intervals['1200001-1800000'] += 1
    
    elif 1800000 < ratings_intervals <= 2400000:
        ratings_intervals['1800001-2400000'] += 1
        
    elif 2400000 < ratings_intervals <= 3000000:
        ratings_intervals['2400001-3000000'] += 1
        
    else:
        ratings_intervals['3000000+'] += 1
        
print(ratings_intervals)        
        

What I expected to happen: The values of the dictionary to be properly distributed in the intervals

What actually happened: All values were just dumped into the first interval

{'1200001-1800000': 0, '600001-1200000': 0, '3000000+': 0, '1800001-2400000': 0, '2400001-3000000': 0, '0-600000': 7197}

I’m not sure why my code isn’t working. All values of the dictionary are placed only into the first interval, all other intervals have 0 value.

Hello @s.cook20 you need to define ratings_count_tot in your second for loop. The value that is currently being used in the second loop is the last value from the first for loop.

Thank you! I also found a typo bust where I switched from ratings_count_tot to ratings_intervals in my elifs on accident.

1 Like