Filtering for intervals

Hello, I am having issue with this particular lesson. When I Loop over rating_count_tot to create frequency table with intervals the code doesn’t run. But it runs just fine when I loop over apps_data. Why is that?
rating_count_tot =
for row in apps_data[1:]:
ratings = float(row[5])
rating_count_tot.append(ratings)
Max = max(rating_count_tot)
Min = min(rating_count_tot)
print(rating_count_tot)

Dictionary = {‘0 - 650000’ : 0, ‘650000 - 1300000’ : 0, ‘1300000 - 1950000’ : 0, ‘1950000 - 2600000’ : 0, ‘2600000 - 3000000’ : 0}

for thing in rating_count_tot:
Data = rating_count_tot[thing]
if Data <= 650000:
Dictionary [‘0 - 650000’] += 1
elif 650000 < Data <= 1300000:
Dictionary [‘650000 - 1300000’] += 1
goes on

Welcome to DQ Community @ShamsulHoqueKhan

Please ignore this if you were able to solve this question.

Kindly follow this post to ask a question that is easy to understand by the other members so that they are able to help you more efficiently.

Coming to the code:

  1. I am not sure why this line doesn’t give you an error?
    ratings = float(row[5]).
    I am assuming apps_data means the google play store data here.
    The reason why I want to understand this line better is, it has values like “5,000,000+”. So in order to make it float or int type, we will first have to get rid of + and then , to make it something like 5000000.0 or 5000000.

  2. Since ratings_count_tot is a list, this code should also give you an error.

Here you only need the for loop for the counter.

Then inside the for loop the Data should be replaced by thing like as below:

for thing in rating_count_tot:
#     Data = rating_count_tot[thing] # You don't need this as rating_count_tot is a list and not a dictionary!
    if thing <= 650000: # inplace of Data <= 650000
        # Some code
    elif 650000 < thing <= 1300000:
        # some other code
  1. Why not use variable names which:
  • are Not keywords like Dictionary or data (this is a keyword when you will come to data visualization if it’s in your learning path)
  • make sense! I can even write for alien in rating_count_tot but it won’t be sensible or right.