Skip to content

Instantly share code, notes, and snippets.

@rahimnathwani
Created March 24, 2012 03:33
Show Gist options
  • Select an option

  • Save rahimnathwani/2177926 to your computer and use it in GitHub Desktop.

Select an option

Save rahimnathwani/2177926 to your computer and use it in GitHub Desktop.
Trim the second field in a CSV file down to 3999 characters
import csv
csvReader = csv.reader(open('input.csv','rb'), delimiter=',',quotechar='"')
csvWriter = csv.writer(open('output.csv','wb'), delimiter=',',quotechar='"',quoting=csv.QUOTE_MINIMAL)
for row in csvReader:
csvWriter.writerow([row[0],row[1][0:3998],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10],row[11],row[12]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment