At the beggining of my code, I define android here:
opened_file = open('AppleStore.csv', encoding="utf8")
from csv import reader
read_file = reader(opened_file)
apple = list(read_file) # This assigns the list representation of the CSV file to the variable apple. Now, apple is a list of lists where each inner list corresponds to a row in the CSV file.
apple_header = apple[0] #returns header row of AppleStore.csv
apple = apple[1:] #returns all rows from row 2 and onwards of AppleStore.CSV
opened_file = open('googleplaystore.csv', encoding="utf8")
from csv import reader
read_file = reader(opened_file)
android = list(read_file)
android_header = android[0]
android = android[1:]
However, when I add this code:
android_reviews_max = {}
for row in android:
name = row[0]
n_reviews = float(row[3])
if name in android_reviews_max and android_reviews_max[name] < n_reviews:
android_reviews_max[name] = n_reviews
elif name not in android_reviews_max:
android_reviews_max[name] = n_reviews
number_android_entries_reviews_max = print(len(android_reviews_max))
apple_reviews_max = {}
for row in apple:
name = row[0]
n_reviews = float(row[6])
if name in apple_reviews_max and apple_reviews_max[name] < n_reviews:
apple_reviews_max[name] = n_reviews
elif name not in reviews_max:
apple_reviews_max[name] = n_reviews
number_apple_entries_reviews_max = print(len(apple_reviews_max))
I get an error saying:
NameError Traceback (most recent call last)
<ipython-input-6-78ffa36fa94f> in <module>
1 android_reviews_max = {}
----> 2 for row in android: #note: using a for loop, the variable must be the same if you want to call a certain element on a row (or sublist). In this case, the variable is row. Notice on the next two lines, I use this variable to call certain elements of the row (sublist).
3 name = row[0]
4 n_reviews = float(row[3])
5 if name in android_reviews_max and android_reviews_max[name] < n_reviews:
NameError: name 'android' is not defined
How is "android" not defined when it is explicity defined at the top?