python - CSV Problems and Help Needed with Code -


so trying create python script sort specified column of excel sheet. far code is...

import csv import operator  open('case_name.csv') infile:     data = list(csv.reader(infile, dialect=csv.excel_tab))  data.sort(key=operator.itemgetter(2))  open('case_name_sorted.csv', 'w') outfile:     writer = csv.writer(outfile, dialect='excel')     writer.writerows(data) 

however, when run code continue error says...

data = list(csv.reader(infile, dialect=csv.excel_tab)) _csv.error: new-line character seen in unquoted field - need open file in universal-newline mode? 

i did research , found out .csv files not work on mac. should change file keep working excel sheet? also, if has pointers on how else sort column, appreciate tips. thanks!

try opening file mode

open('case_name.csv', mode='ru') 

compare with: https://docs.python.org/2/library/functions.html#open


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -