GP: Profitable App Profiles for the App Store and Google Play Markets

I’m receiving an error on the guided project on step 5. I want to remove duplicates and add the apps with the most reviews. I checked and copied the solution:

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[name] = n_reviews
    
elif name not in reviews_max:
    reviews_max[name] = n_reviews

But I still receive an error saying that it can’t convert strings to float (the string is 13M). Is this a bug, and how do I make it work?

Thanks in advance

Hey there Pepijn!! Welcome to our forums, we’re excited to have you participate here!

Just a couple of things to mention first since you’re new!

  1. If possible, do try to link to the mission/screen you had your issue on. Makes it easier on others!
  2. If someone’s solution works, do mark it as “solved”, as outlined here. This helps other students find the solution if they had a similar query!

As to your question, the reason you’re having that issue is because you’re simply indexing the wrong column. You’re supposed to be indexing the Reviews column, but you’re actually indexing the Size column. You can’t convert it to float because the Size column includes the unit “M” (which I presume has to mean “Megabytes”!)

As a side note, this means you’re also almost certainly indexing the wrong App column when you’re doing name = app[0]. Try and check what the values in that column currently are - they should be the names of the apps!

Did you read in the list of lists correctly? You should have done the following:

opened_file = open('googleplaystore.csv')
read_file = reader(opened_file)
android = list(read_file)
android_header = android[0]
android = android[1:]

I’d also check your previous steps to see if you might have accidentally gotten rid of one of the earlier values in the list.

1 Like

Thank you, the problem was that I had put the delete line 10472 as a comment, because I didn’t want to run it again. So the 3.0M was the size of that app.

Ah, that would do it! Glad you sorted it out!

Do remember to mark a post as Solved if it helped sort out your issue - this helps other students find the solution too!

How did you solve this?

I’m so happy that i discovered and solved the bug.

Steps i took

had to find the length of my Andriod

print(Andriod[10472])
[‘Life Made WI-Fi Touchscreen Photo Frame’, ‘1.9’, ‘19’, ‘3.0M’, ‘1,000+’, ‘Free’, ‘0’, ‘Everyone’, ‘’, ‘February 11, 2018’, ‘1.0.19’, ‘4.0 and up’]

i now compared it with the length of the previous andriod

print(Andriod[10471])
[‘Xposed Wi-Fi-Pwd’, ‘PERSONALIZATION’, ‘3.5’, ‘1042’, ‘404k’, ‘100,000+’, ‘Free’, ‘0’, ‘Everyone’, ‘Personalization’, ‘August 5, 2014’, ‘3.0.0’, ‘4.0.3 and up’]

actually the float(app[3]) from the Andriod[10472] was showing ‘3.0M’ which was has a string value attached to it.

but Andriod[10471] showed ‘1042’ which are integers. had to delete Andriod[10472]

and when i performed

reviews_max = {}
for app in Andriod:
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

it worked out with the corresponding value

print(‘Expected length:’, len(Andriod) - 1181)
print(‘Expected length:’, len(reviews_max))
showing this.
Expected length: 9659
Expected length: 9659