Solution code and my code are both not working

For Introduction to Python, Guided Project: Profitable App Profiles for the App Store and Google Play Markets - Step 5/14 the code is not working to create a dictionary because float can not convert a value.

Below is the code:

reviews_max = {}

for app in g_apps_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



ValueErrorTraceback (most recent call last)
in ()
3 for app in g_apps_data[1:]:
4 name = app[0]
----> 5 n_reviews = float(app[3])
7 if name in reviews_max and reviews_max[name] < n_reviews:

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

hey @donniegoode

float won’t be able to convert string character “M”.

You will have to add a step before completing this step. You will have to remove any characters from the “rating” column first and then the dictionary step would follow.

Alright, I figured out the issue. Because of row 10473 not being deletable, the “Size” cell value of “3.0M” is in the “Reviews” cell value. Below is the code used to find/diagnose the problem:


for app in g_apps_data:
reviews = app[3]
if reviews == ‘3.0M’:


[‘App’, ‘Category’, ‘Rating’, ‘Reviews’, ‘Size’, ‘Installs’, ‘Type’, ‘Price’, ‘Content Rating’, ‘Genres’, ‘Last Updated’, ‘Current Ver’, ‘Android Ver’]

[‘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 had mentioned being unable to delete row 10473 in this topic but haven’t received a response yet. If @Rucha knows a fix or workaround for removing the row that would be great. I am thinking about just going into the text file and removing it there since executing ‘del’ on the row does not work.

A little error handling helped me out with this one. This way anything that can’t be converted to a float will be deleted

    n_reviews = float(app[3])
except ValueError:
    del app```
1 Like