Filtering for the Intervals: TypeError: 'int' object is not subscriptable

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

The code I put in:
"rating_count_total =

for row in apps_data[1:]:
rating = int(row[5])
rating_count_total.append(rating)

ratings_min = min(rating_count_total)
ratings_max = max(rating_count_total)

for row in apps_data[1:]:
data_size = int(row[5])

if data_size <= 500000:
    data_size['0 - 500000'] +=1
    
elif 500000 < data_size <= 1000000:
    data_size['500000 - 1 mill'] += 1

elif 1000000 < data_size <= 1500000:
    data_size['1 mill - 1.5 mill'] += 1

elif 1500000 < data_size <= 2000000:
    data_size['1.5 mill - 2 mill'] += 1
    
elif 200000 < data_size <= 2500000:
    data_size['2 mill - 2.5 mill'] += 1

else:
    data_size['2.5 mill +'] += 1

print(data_size)"

The error I received:
TypeErrorTraceback (most recent call last)
in ()
32
33 else:
β€”> 34 data_size[β€˜2.5 mill +’] += 1
35
36

TypeError: β€˜int’ object is not subscriptable

Hi @liz.tracy09

Welcome to our Dataquest Community.

You are using the data_size variable as integer type and also trying to use it as a dictionary data type. That’s why it gives a TypeError.

I hope you will figure out what you have to edit, need more help let me know :slightly_smiling_face: .

1 Like

Ok my problem is that I don’t see it – I looked at the answer code and it’s identical except for the variables are different. This is where I’m stuck as I’m obviously missing something but unless I use identical variables I’m not sure what it is.

Hi @liz.tracy09,

I hope this will help you to see the difference:

Best,
Sahil

1 Like

It totally does – I just couldn’t see it before so thank you!

2 Likes

My code is:

rating_count_tot = []
for row in apps_data[1:]:
    rating_count_tot.append(float(row[5]))
ratings_max=max(rating_count_tot)
ratings_min=min(rating_count_tot)

level1 = (((ratings_max-ratings_min) / 5)*1) + ratings_min
level2 = (((ratings_max-ratings_min) / 5)*2) + ratings_min
level3 = (((ratings_max-ratings_min) / 5)*3) + ratings_min
level4 = (((ratings_max-ratings_min) / 5)*4) + ratings_min

key1 = 'tot < ' + str( level1)
key2 = str(level1) + ' < tot <= ' + str(level2)
key3 = str(level2) + ' < tot <= ' + str(level3)
key4 = str(level3) + ' < tot <= ' + str(level4)
key5 = str(level4) + ' < tot'
rating_count_tot_dic={key1:0,key2:0,key3:0,key4:0,key5:0}

for row in rating_count_tot:
    if row <= level1:
        rating_count_tot_dic[key1] += 1
    elif level1 < row <= level2:
        rating_count_tot_dic[key2] += 1
    elif level2 < row <= level3:
        rating_count_tot_dic[key3] += 1
    elif level3 < row <= level4:
        rating_count_tot_dic[key4] += 1
    elif row > level4:
        rating_count_tot_dic[key5] += 1

Hi Guys I have an issue here with validating the codes everything seems good can someone please check and tell me what i am missing here ?
Alpha =
for elem in apps_data[1:]:
Alpha.append(int(elem[5]))

ratings_max = max(Alpha)
ratings_min = min(Alpha)

rank={β€˜0-500’:0,β€˜500-1000’:0,β€˜1000-2000’:0,β€˜2000+’:0}

for elem in apps_data[1,]:
count=int(elem[5])
if count<=500000:
rank[β€˜0-500’]+=1
elif 500000<count<=1000000:
rank[β€˜500-1000’]+=1
elif 1000000<count<=2000000:
rank[β€˜1000-2000’]+=1
elif count>2000000:
rank[β€˜2000+’]+=1

print(rank)


this is the error message I am getting
TypeErrorTraceback (most recent call last)
in ()
16 rank={β€˜0-500’:0,β€˜500-1000’:0,β€˜1000-2000’:0,β€˜2000+’:0}
17
β€”> 18 for elem in apps_data[1,]:
19 count=int(elem[5])
20 if count<=500000:

TypeError: list indices must be integers, not tuple

Hey Abdel, it looks like you have a comma inside the brackets instead of a colon:

for elem in apps_data[1,]:

Oh it is my friend thank you so much everything is good now