質問編集履歴

1

Pythonでトライした場合のコードを記載しました。

2019/10/26 10:14

投稿

Oshiete_sensei
Oshiete_sensei

スコア4

test CHANGED
File without changes
test CHANGED
@@ -32,11 +32,27 @@
32
32
 
33
33
  ### 該当のソースコード
34
34
 
35
+ ```
36
+
35
37
  cat 該当ファイル|awk '$1!=prev{close(out); out=$1".txt"; prev=$1}{sub(/[^\t]+\t/,""); {sub(/,"");print > out}'
36
38
 
37
- ```ここに言語名を入力
39
+ ```
38
40
 
41
+ ```
42
+
43
+ #Pythonでやった場合(2019/10/26追記)
44
+
45
+ import csv
46
+
47
+
48
+
49
+ with open('対象データセット.csv') as csvfile:
50
+
51
+ for i, line in enumerate(csvfile):
52
+
53
+ with open("{}.txt".format(str(i+1)), "w") as txtfile:
54
+
39
- awk, Python(pandas)
55
+ txtfile.write(line)
40
56
 
41
57
  ```
42
58
 
@@ -44,7 +60,17 @@
44
60
 
45
61
  ### 試したこと
46
62
 
63
+ import csv
47
64
 
65
+
66
+
67
+ with open('対象データセット.csv') as csvfile:
68
+
69
+ for i, line in enumerate(csvfile):
70
+
71
+ with open("{}.txt".format(str(i+1)), "w") as txtfile:
72
+
73
+ txtfile.write(line)
48
74
 
49
75
  awk, Python(pandas)などで目的の処理をやろうとしていますが、うまくいっていません。
50
76