Guided Project: Profitable App Profiles (unexpected type error when cleaning data)

Screen Link: https://app.dataquest.io/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/5/removing-duplicate-entries-part-two

My Code: <

reviews_max = {}

for app in android:
    name = app[0]
    n_reviews = float(app[3])
    
    if name in reviews_max and reviews_max[name] < n_reviews:
        reviews_max = n_reviews
    elif name not in reviews_max:
        reviews_max[name] = n_reviews
print(len(reviews_max))

What I expected to happen:

I attempted to create a subset of the Google Play Store data without the duplicates.
What actually happened:

TypeError                                 Traceback (most recent call last)
<ipython-input-25-eb1c7199cb62> in <module>
      5     n_reviews = float(app[3])
      6 
----> 7     if name in reviews_max and reviews_max[name] < n_reviews:
      8         reviews_max = n_reviews
      9     elif name not in reviews_max:

TypeError: argument of type 'float' is not iterable

I’m not sure why I’m getting this error, my code is identical to the given solution code. Thanks for your help!

1 Like

Here, specifically name in reviews_max you are using reviews_max with in operator. and reviews_max is float. You can not use in with float type hence you are getting error.

2 Likes

I get a different error - i know why - i just have not figured out how to solve it.
**ValueError** Traceback (most recent call last) **<ipython-input-26-4763584950ea>** in <module> 2 **for** app **in** android**:** 3 name **=** app**[** **0** **]** **----> 4** n_reviews **=** float**(** app**[** **3** **]** **)** 5 6 **if** name **in** reviews_max **and** reviews_max**[** name**]** **<** n_reviews**:** **ValueError** : could not convert string to float: '3.0M'

That’s because row 10474 in the googleplaystore.csv, column 4 actually has a string “3.0M” and the code is throwing a ValueError exception. I’m trying to trap the error and kick off a code snippet changes it to a float value of 3,000,000.00 and processes it again. I’ve not ben very successful so far.

Hi @DishinGoyani, I have the same (exact) error from this same step as posted by @AmandaGarcia. How do I solve this? How come this same line of code is said to have worked in the solution code? Grateful for any help on this. Thank you.

@AmandaGarcia Hello! Did you find the problem? I had the same TypeError myself, and I think you getting this error for the same reason I did, it’s just a simple mistake

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

Hello @firoz.rangwala Sir,
I am also getting the same error if you able to rectify it please help me.

Thank you.

Hi,
Here after if statement you are just writing reviews_max =n_reviews. Instead of this this you have to write reviews_max[name] = n_reviews.Hope you will find this helpful.