Python Forum
SyntaxError: invalid syntax
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SyntaxError: invalid syntax
#1
I'm working on some problem and the goal is to count the frequency of each interval. There is a table with ratings ( sixth row ).

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
user_ratings = []
for row in apps_data[1:]:
    n_user_ratings.append(int(row[5])
                        
ratings_max = max(n_user_ratings)
ratings_min = min(n_user_ratings)
                       
user_ratings_freq = {'0 - 10000': 0, '10000 - 100000': 0, '100000 - 500000': 0,'500000 - 1000000': 0, '1000000+': 0}
    
for row in apps_data[1:]:
    user_ratings = int(row[5])
                        
    if user_ratings <= 10000:
        user_ratings_freq['0 - 10000'] += 1
        
    elif 10000 < user_ratings <= 100000:
        user_ratings_freq['10000 - 100000'] += 1
        
    elif 100000 < user_ratings <= 500000:
        user_ratings_freq['100000 - 500000'] += 1
        
    elif 500000 < user_ratings <= 1000000:
        user_ratings_freq['500000 - 1000000'] += 1
        
    elif user_ratings > 1000000:
        user_ratings_freq['1000000+'] += 1
                        
print(user_ratings_freq)
Error:
ratings_max = max(n_user_ratings) ^ SyntaxError: invalid syntax
Any idea why this error appeared?
Reply
#2
Search your code for other occurrences of max.
My guess would be that it got redefined somewhere, probably by mistake.
Reply
#3
Count parentheses on line-7.
Reply
#4
(Mar-10-2020, 02:45 AM)snippsat Wrote: Count parentheses on line-7.

after I made a correction got this error:
Error:
NameErrorTraceback (most recent call last) <ipython-input-1-0c555430149c> in <module>() 5 user_ratings = [] 6 for row in apps_data[1:]: ----> 7 n_user_ratings.append(int(row[5])) 8 9 ratings_max = max(n_user_ratings) NameError: name 'n_user_ratings' is not defined
...and made a correction in line 5 and now it's OK. Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to find what is causing the unboundlocalerror 'crumb' and invalid syntax error? JonathanBanks 1 2,292 Jul-28-2020, 11:46 AM
Last Post: Yoriz
  list comprehension invalid syntax mcgrim 1 4,674 Jun-12-2019, 08:28 PM
Last Post: Yoriz
  %matplotlib inline , invalid syntax yamoon 1 13,067 Jul-12-2018, 07:22 AM
Last Post: volcano63
  Misterious invalid syntax Galedon 3 3,466 Mar-30-2018, 03:49 PM
Last Post: Galedon

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020