Easy CSV transposition I wondered how many lines it would take
csvt.py
# -*- coding: utf-8 -*-
import sys
import numpy
fin = open(sys.argv[1], "r")
fout = open(sys.argv[2], "w")
for line in numpy.array([s.strip('\n').split(',') for s in fin]).T:
fout.write(",".join(line) + "\n")
fin.close()
fout.close()
Run
python csvt.py in.csv out.csv
in.csv
1,2,3
4,5,6
7,8,9
out.csv
1,4,7
2,5,8
3,6,9
Recommended Posts