5
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonでCSVファイルを転置する その1

Last updated at Posted at 2017-07-20

お手軽にCSV転置
何行くらいかかるかと思って書いてみた

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()
実行
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

続きます。

5
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?