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

質問編集履歴

2

追記

2018/11/27 09:03

投稿

kanpan
kanpan

スコア20

title CHANGED
File without changes
body CHANGED
@@ -43,4 +43,61 @@
43
43
  if i == 12:
44
44
  print(count)
45
45
  ```
46
- にしたらcountの値が出力すらされませんでした。
46
+ にしたらcountの値が出力すらされませんでした。
47
+
48
+ #解決後のプログラム
49
+ ```
50
+ import csv
51
+
52
+ csv_file = open("./posneg_train.csv", "r", encoding="ms932", errors="", newline="" )
53
+ f1 = csv.reader(csv_file, delimiter=",", doublequote=True, lineterminator="\r\n", quotechar='"', skipinitialspace=True)
54
+
55
+ i = 0
56
+ stri = str(i+1)
57
+ count = 0
58
+ start = 0
59
+ end = 350
60
+ data = open('posneg_train_'+ stri + '.csv','w',newline="")
61
+ for row in f1:
62
+ if count < start:
63
+ count += 1
64
+ continue
65
+ if count >= end:
66
+ data.close()
67
+ i += 1
68
+ stri = str(i+1)
69
+ start = count
70
+ end = start + 350
71
+ data = open('posneg_train_'+ stri + '.csv','w',newline="")
72
+
73
+ if count == start:
74
+ w = csv.writer(data)
75
+ w.writerow([row[0],row[1]])
76
+ count += 1
77
+ csv_file = open("./posneg_test.csv", "r", encoding="ms932", errors="", newline="" )
78
+ f2 = csv.reader(csv_file, delimiter=",", doublequote=True, lineterminator="\r\n", quotechar='"', skipinitialspace=True)
79
+
80
+ i = 0
81
+ stri = str(i+1)
82
+ count = 0
83
+ start = 0
84
+ end = 350
85
+ data = open('posneg_test_'+ stri + '.csv','w',newline="")
86
+ for row in f2:
87
+ if count < start:
88
+ count += 1
89
+ continue
90
+ if count >= end:
91
+ data.close()
92
+ i += 1
93
+ stri = str(i+1)
94
+ start = count
95
+ end = start + 350
96
+ data = open('posneg_test_'+ stri + '.csv','w',newline="")
97
+
98
+ if count == start:
99
+ w = csv.writer(data)
100
+ w.writerow([row[0],row[1]])
101
+ count += 1
102
+
103
+ ```

1

追記

2018/11/27 09:03

投稿

kanpan
kanpan

スコア20

title CHANGED
File without changes
body CHANGED
@@ -38,4 +38,9 @@
38
38
  ```
39
39
  for row in f1:
40
40
  ```
41
- のあとに挿入してみた結果、countの値が3333で止まっていることが確認されました。
41
+ のあとに挿入してみた結果、countの値が3333で止まっていることが確認されました。
42
+ ```
43
+ if i == 12:
44
+ print(count)
45
+ ```
46
+ にしたらcountの値が出力すらされませんでした。