Problem in conditional statement section

Screen Link:
https://app.dataquest.io/m/313/conditional-statements/4/the-average-rating-of-gaming-apps

My Code:

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
non_games_ratings=[]
for row in apps_data[1:]:
    rating=float(row[7])
    genre=row[11]
    if genre!='Games':
        non_games_ratings.append(rating)
avg_rating_non_games=sum(non_games_ratings)/len(non_games_ratings)
print(avg_rating_non_games)

What I couldn’t understand:
Why do we use row[7] for assigning the ratings.We know that indexing starts from 0.So,shouldn’t it be row [6]

Here’s the screen snip
dq1

These are the column names along with their indices -

  1. id
  2. track_name
  3. size_bytes
  4. currency
  5. price
  6. rating_count_tot
  7. rating_count_ver
  8. user_rating

As you can see, row[7] would correspond to user_rating.

Why do we write if statement inside the for loop?
I tried writing the if statement outside the for loop but that affects the output. I get the output as 0 when if statement is written outside the for loop. Why?

Please ask your question in a separate/new post. Best to have a separate post for every question.

1 Like