Doubt regarding the column index

Hello, I have a doubt regarding the column index. I wrote this code in pycharm and the output is the same as the answer of the exercise but it’s showing an error when I submit the answer. I had to change the column index to 7 in order to get it right. Can someone help me understand why am I getting the correct result using 8 as the column index in pycham but dataquest is not accepting it?

import csv

opened_file = open(‘AppleStore.csv’, encoding=“utf8”)
read_file = csv.reader(opened_file)
apps_data = list(read_file)

header = apps_data[0]
rating_sum = 0

for row in apps_data[1:]:

rating = float(row[8])
rating_sum = rating_sum + rating

row_count = len(apps_data[1:])
avg_rating = rating_sum / row_count
print(avg_rating)

Hi @medinacr96,

As far as I understood, you are talking about Lists and Loops mission.

If we look at the “header” of the list of lists apps_data (i.e., at apps_data[0]), we see the following output:


['id',
 'track_name',
 'size_bytes',
 'currency',
 'price',
 'rating_count_tot',
 'rating_count_ver',
 'user_rating',
 'user_rating_ver',
 'ver',
 'cont_rating',
 'prime_genre',
 'sup_devices.num',
 'ipadSc_urls.num',
 'lang.num',
 'vpp_lic']

Hence if later, in your for-loop, you write row[8], considering that Python has 0-indexing, it means 'user_rating_ver'. Otherwise, if you write row[7], it means 'user_rating'. So, they are technically both ratings, but of different kinds (from different groups of users, or somehow modified, etc.).

Exactly in that mission the task is to use 'user_rating', otherwise the answer will not pass submitting process. That’s why on you local computer you can use, if you want, row[8], which means just another kind of rating ('user_rating_ver'), and you will not get any error, since technically there is no issue with it. But on the DQ platform you will get an error, since this is not the rating required in the task.

1 Like

@medinacr96 In future please format your code using backticks (below the Esc button on your keyboard i.e. ` ) and not using the quote symbol (>) so that our volunteers can more easily spot incorrect indentations if any. Here is a markdown cheatsheet that I use when using markdown both in jupyter and in the community.

Thanks