Regarding invalid syntax error



I am getting the following error attached in the screenshot below when i try to convert a number into percentage in python.Can anyone tell me why this error occurs?


As you are using map function along with the field, use split function.

thank you


@padmavathi As you said I used split function inside map function but i am getting the same error.


Please send the total code. Here if the value in first column is of type int or float, we should typecast.

thank you


@padmavathi The complete code is as follows:

communitycodes=sc.textFile("/user/bigdatakarthik/crime/communitycodes.csv") c:(c.split(",")[5],1))
crimecountbytype= crimeMap.reduceByKey(lambda x,y:x+y) c:(c.split(",")[0],int({:.2%}.format(c.split(",")[1]))))

Note: The error is shown on the colon i have given in the last line


Add quotes for the value which is being formatted. c:(c.split(",")[0],int("{:.2%}".format(c.split(",")[1]))))

Note: First Row of the file is header. As you are not using any method to map the fields excluding header Row, you won’t be able to get any preview for crimecountbytype also.

thank you


@padmavathi When i try to execute the code you have given, i am getting the following error shown in the screenshot attached below:


Use this command: c:(c[0],"{0:.2f}%".format(c[1])))