For loops and Lists, Question 10

I have a question about calculating the average of the ratings

so it is calculated this way :
avg_rating = rating_sum/ len(apps_data[1:])

However to me it does not make sense that we are dividing by apps_data[1:]. apps_data[1:] is all the lists except the headers. It is not just the numbers of ratings.

I would have run the code this way: avg_rating = rating_sum/ len(rating). I get an error saying float has no len()

Can someone please explain why we are deviding by apps_data[1:]

Thank you!


1 Like


rating is an floating point number so there is no len() attribute to it. Only lists and strings have len() as described here.

apps_data[1:] contains the data imported from the csv file excluding the header, which is a list of lists. Thus you can use len() on that. We do this because the number of entries/rows in the apps_data list excluding the header row is also equal to the number of rating entries there are since there are no NaN values in the dataset.

In future, please remember to format your code and provide a question link as per these guidelines.

1 Like

Thank you!/…

1 Like

If you found mind answer helpful do you mind marking it as the solution? Thanks!

1 Like