Skip to content

Instantly share code, notes, and snippets.

@soobrosa
Created March 11, 2014 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soobrosa/9483812 to your computer and use it in GitHub Desktop.
Save soobrosa/9483812 to your computer and use it in GitHub Desktop.
csv transpose
import csv
import sys
infile = sys.argv[1]
outfile = sys.argv[2]
with open(infile) as f:
reader = csv.reader(f)
cols = []
for row in reader:
cols.append(row)
with open(outfile, 'wb') as f:
writer = csv.writer(f)
for i in range(len(max(cols, key=len))):
writer.writerow([(c[i] if i<len(c) else '') for c in cols])
# http://askubuntu.com/questions/74686/is-there-a-utility-to-transpose-a-csv-file
# python my_csv_transposer.py <theinfilename> <theoutfilename>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment