Skip to content

Instantly share code, notes, and snippets.

@atree
Created December 14, 2012 09:09
Show Gist options
  • Save atree/4283900 to your computer and use it in GitHub Desktop.
Save atree/4283900 to your computer and use it in GitHub Desktop.
Quick python script to truncate CSV data elements.
#/usr/bin/python
import csv
fout = open('ptype_out.csv', 'w')
with open('ptype_in.csv', 'rb') as fin:
fin_reader = csv.reader(fin, delimiter='|')
for row in fin_reader:
new_row = ', '.join(row)
new_row = ','.join(new_row.split(',')[:10])
fout.write('"' + new_row + '"\n')
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment