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

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World