Project 1 in Python For Data Analyst Path Code Issue

Hi all,

I am on step 5 of the project 1 in the Python for Data Analyst path and am getting a “type error” even when I use the code from the solution notebook (with the variable names updated).

Can anyone spot what I am doing wrong?

reviews_max = {}

for app in gp_data[1:]:
name = app[0]
n_reviews = float(app[3])

if name in reviews_max and reviews_max[name] < n_reviews:
    reviews_max[name] = n_reviews
    
elif name not in reviews_max:
    reviews_max[name] = n_reviews

reviews_max = {}

for app in gp_data[1:]:
name = app[0]
n_reviews = float(app[3])

if name in reviews_max and reviews_max[name] < n_reviews:
    reviews_max[name] = n_reviews
    
elif name not in reviews_max:
    reviews_max[name] = n_reviews

Expected length: 9660

TypeError Traceback (most recent call last)
in
1 print(‘Expected length:’, len(gp_data)-1180)
----> 2 print(‘Actual length:’, len(n_reviews))

TypeError: object of type ‘float’ has no len()

Thanks, Tim

Hi Tim, welcome to our community!

From the error message you received, it looks like you’re trying to print the length of n_reviews, which is a float value used within your loop. Did you perhaps mean to print the length of the dictionary, reviews_max?

1 Like