ValueError: could not convert string to float: 'Reviews'

Screen Link:

My Code:

reviews_max = {}

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

print('Actual length:', len(reviews_max))

What I expected to happen:

Actual length: 9659

What actually happened:

ValueError                                Traceback (most recent call last)
<ipython-input-11-139af0bd6d30> in <module>
      3 for app in google_data:
      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: 'Reviews'

I have looked into the solutions of other discussion forums with the same issue and tried everything. I tried copying and pasting the code into a new notebook to see if it worked. I have restarted the kernel several times and have gotten the same error again and again.

Are you sure app[3] is a number? The message error is saying you that one of the values assigned to app[3] during the for loop is the string “Reviews”, so it’s impossible to change it to float data type.
When you are stucked like that, a good way to help yourself to debug is to add a print line during the for loop so you will see displayed what value is assigned to app[3] during the for loop.
See:

for app in google_data:
    name = app[0]
    print(app[3])
    n_reviews = float(app[3])

Hi @adcexperiment1234,

You have to exclude the header in the second line of your code:

for app in google_data[1:]:
1 Like

Elena this is cheating you know the course ! :grin:

Wilfried it’s just because I also forgot to exclude the header many times, and probably will yet forget it many times in future :joy:

1 Like

I totally forgot about excluding the header! LOL! And I have trying to figure this out for several hours! Thanks Elena :smiley:

I recommend you to get rid of this header right after data downloading, for not forgetting it anymore :yum:
header = google_data[0]