Guided Project 1: weird stuff

Screen Link: https://app.dataquest.io/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/12/most-popular-apps-by-genre-on-the-app-store

My Code:


for app in googleplay:
    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

What I expected to happen:

Expected length: 9659
Actual length: 9659

What actually happened:

ValueErrorTraceback (most recent call last)
<ipython-input-10-67231840bcc1> in <module>()
      3 for app in googleplay:
      4     name = app[0]
----> 5     n_reviews = float(app[3])
      6     if name in reviews_max and reviews_max[name] < n_reviews:
      7         reviews_max[name] = n_reviews

ValueError: could not convert string to float: '3.0M'

The most puzzling thing about this is that the code actually used to run before. In the meantime I have written a lot more below, and then suddenly after I did “restart & run all” this started showing up. There is no way I can understand why a code used to run before and now does not. the ‘3.0M’ should have been there before, so why did it somehow appear?

By the way, this is the exact same code as the answer, the only difference is that googleplay is called android there. I wish there was any kind of logical explanation, because now it is really frustrating and I can’t finish the project because I already have the solution right in front of me.

I hope you are able to help me.

Hi @DavidMiedema. This issue has been addressed before. Here is a link to the article

Let me quote @bvalgard.

If you look at the error message you can see that it is giving you a clue to where the problem is.

ValueError: could not convert string to float: ‘3.0M’

It is saying that somewhere in the data we are trying to convert to a float there is a string ‘3.0M’ that it cannot convert. The problem is the ‘M’ at the end of the string. For this project, the best way to fix this problem is to just delete the row with the problem data.

del android[10472] # don’t run this more than once

As explained in the guided project, the following post explains that there is an error for entry 10472 (that’s why we are deleting that entry).



Perhaps, You may wish to search for articles in the future about similar issues that others may have faced as indicated in the image above to avoid duplicated answers in the community and save some time awaiting a reply on your end.

Hope this helps!

3 Likes

Thank you for your help!

So when I run the whole code again it forgets about the delete command I did earlier. That means every time I run the code again I should delete the line again. It seems a bit impractical.

Yes I should think so! Everytime you rerun a jupyter notebook, the local variables are cleared out of memory. No worries!