Error with content_rating Dic

Screen Link:

My Code:
opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
content_ratings = {}

for rows in apps_data[1:]:
c_rating = row[10]
if c_rating in content_ratings:
content_ratings[c_rating] += 1
else:
content_ratings[c_rating] = 1

print(content_ratings)

Replace this line with your code

What I expected to happen:
I thought it would be right considering I completed all instructions.

What actually happened:
my dictionary for the content_rating came out completely different, with only one element.

{'4+': 7197}
Replace this line with the output/error

Hey @nicole.vasquez9.jv

Welcome to Data Quest Community!

As per my understanding it is because that you are printing the (content_ratings ) with in the conditional statements. Try printing the (content_ratings ) outside conditional statements, i believe you should get the desired output.

And also please make sure to add the screen link details from next time for better understanding of the problem.

Let me know if your problem is solved.

Best
K!

1 Like

Hi @nicole.vasquez9.jv,
As the code is not formatted in your post, it is difficult to know why you are getting the output you got. If the print statement is within the for loop or the if statement, you are likely to get multiple lines of output. Structure your code as below and you get the expected output.

image

Hopefully, this helps!

1 Like