Skip to content

Instantly share code, notes, and snippets.

@dalanlan
Created June 20, 2016 08:51
Show Gist options
  • Select an option

  • Save dalanlan/75891749fd1d226b5a6b93e9cc66b84a to your computer and use it in GitHub Desktop.

Select an option

Save dalanlan/75891749fd1d226b5a6b93e9cc66b84a to your computer and use it in GitHub Desktop.
sort csv file
import csv
import sys
import operator
reload(sys)
sys.setdefaultencoding('utf-8')
reader = csv.reader(open(str(sys.argv[1])), delimiter="|")
sortedlist = sorted(reader, key=operator.itemgetter(8))
with open(str(sys.argv[2]), 'wb') as csvfile:
writer = csv.writer(csvfile, delimiter = "|")
writer.writerows(sortedlist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment