Finding the Unique Values

Python for Data Science: Fundamentals
Dictionaries And Frequency Tables
8.Finding the Unique Values


opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

content_ratings = {}

for each_row in apps_data[1:]:
c_ratings = each_row[10]
if c_rating in content_ratings:
content_ratings[c_rating] += 1
else:
content_ratings[c_rating] = 1

content_ratings

–> {‘4+’: 7197} instead of {‘12+’: 1155, ‘17+’: 622, ‘4+’: 4433, ‘9+’: 987}


Where am I wrong?
PS: HELP button does not work (neither on Chrome nor Firefox)

You meant to make c_ratings and c_rating the same variable, but because you spelled it differently each time, they’re two separate variables!

1 Like

Thank you!
I am too distracted!

Ya, no problem at all. Happens all the time to everyone! And by the way, welcome to the forums :slight_smile:

I’d also suggest that when you copy-paste code onto the forums, you envelop it using 3 back ticks (```) before and after the code, so it appears as a proper coded block and thus looks more readable!

3 Likes