Skip to content

Instantly share code, notes, and snippets.

@ah89
Created October 3, 2018 10:55
Show Gist options
  • Save ah89/bf2397bb0143a955896192e3641c4334 to your computer and use it in GitHub Desktop.
Save ah89/bf2397bb0143a955896192e3641c4334 to your computer and use it in GitHub Desktop.
Add index in big csv
import csv
input_file_path = 'soccer_clean_flat.csv'
output_file_name = 'soccer_clean.csv'
f = open(input_file_path)
csv_f = csv.reader(f)
header = csv_f.next()
f2 = open(output_file_name, 'w')
f2.write('{},{},{}\n'.format(header[0], header[1], header[2]))
for r in csv_f:
f2.write('{},{},{}\n'.format(str(int(r[0]) + 1), r[1], r[2]))
f.close()
f2.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment