Created
March 11, 2014 11:15
-
-
Save soobrosa/9483812 to your computer and use it in GitHub Desktop.
csv transpose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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