teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2018/07/31 12:53

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -35,4 +35,24 @@
35
35
  with open('dst.csv', 'w') as f:
36
36
  for elem in data2[0]:
37
37
  print(elem, file=f)
38
+ ```
39
+
40
+ コメントを受けて
41
+ ---
42
+ ```plain
43
+ 1.1,1.2,1.3
44
+ 2.1,2.2,2.3
45
+ ```
46
+
47
+ ```Python
48
+ import csv
49
+
50
+ with open('src.csv') as fin:
51
+ data = []
52
+ for row in csv.reader(fin):
53
+ data.append(row)
54
+
55
+ data = zip(*data)
56
+ with open('dst.csv', 'w') as fout:
57
+ csv.writer(fout).writerows(data)
38
58
  ```