質問編集履歴
1
追加コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,11 +66,137 @@
|
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
-
### 試したこと
|
69
|
+
### 試したこと(コード)
|
70
|
+
|
70
|
-
|
71
|
+
```
|
72
|
+
|
73
|
+
import pandas as pd
|
74
|
+
|
75
|
+
import time
|
76
|
+
|
77
|
+
import csv
|
78
|
+
|
79
|
+
import numpy as np
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
df_new = open(r'new.csv','a',newline="")
|
84
|
+
|
85
|
+
csvWriter = csv.writer(df_new)
|
86
|
+
|
87
|
+
listData = ['year','month','day','ID1','ID2','A,'B','C','D','E','F','G','H','I','gyoretsu']
|
88
|
+
|
89
|
+
csvWriter.writerow(listData)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
gyoretsu=[]
|
94
|
+
|
95
|
+
start=time.time()
|
96
|
+
|
97
|
+
with open(r'元データ.csv','r')as df:
|
98
|
+
|
99
|
+
num = 0
|
100
|
+
|
101
|
+
for line in df:
|
102
|
+
|
103
|
+
num += 1
|
104
|
+
|
105
|
+
if(num == 1):
|
106
|
+
|
107
|
+
print("読み込み開始")
|
108
|
+
|
109
|
+
else:
|
110
|
+
|
111
|
+
if(num%100 == 0):
|
112
|
+
|
113
|
+
print("num={0},".format(num),end="")
|
114
|
+
|
115
|
+
elapsed_time = time.time() - start
|
116
|
+
|
117
|
+
print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
|
118
|
+
|
119
|
+
line = line.rstrip('\n').split(',')
|
120
|
+
|
121
|
+
if(line[16]==1):
|
122
|
+
|
123
|
+
a = np.loadtxt(r'A.csv', delimiter=',', dtype='object',encoding='utf-8')
|
124
|
+
|
125
|
+
elif(line[17]==1):
|
126
|
+
|
127
|
+
a= np.loadtxt(r'B.csv', delimiter=',', dtype='object',encoding='utf-8')
|
128
|
+
|
129
|
+
elif(line[18]==1):
|
130
|
+
|
131
|
+
a= np.loadtxt(r'C.csv', delimiter=',', dtype='object',encoding='utf-8')
|
132
|
+
|
133
|
+
elif(line[19]==1):
|
134
|
+
|
135
|
+
a= np.loadtxt(r'D.csv', delimiter=',', dtype='object',encoding='utf-8')
|
136
|
+
|
137
|
+
elif(line[20]==1):
|
138
|
+
|
139
|
+
a= np.loadtxt(r'E.csv', delimiter=',', dtype='object',encoding='utf-8')
|
140
|
+
|
141
|
+
elif(line[21]==1):
|
142
|
+
|
143
|
+
a= np.loadtxt(r'F.csv', delimiter=',', dtype='object',encoding='utf-8')
|
144
|
+
|
145
|
+
elif(line[22]==1):
|
146
|
+
|
147
|
+
a= np.loadtxt(r'G.csv', delimiter=',', dtype='object',encoding='utf-8')
|
148
|
+
|
149
|
+
elif(line[23]==1):
|
150
|
+
|
151
|
+
a= np.loadtxt(r'H.csv', delimiter=',', dtype='object',encoding='utf-8')
|
152
|
+
|
153
|
+
elif(line[24]==1):
|
154
|
+
|
155
|
+
a= np.loadtxt(r'I.csv', delimiter=',', dtype='object',encoding='utf-8')
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
def gyoretsu(ID1,ID2):
|
160
|
+
|
161
|
+
if((np.any(a[:,0]== ID1) and np.any(a[0,:]== ID2))):
|
162
|
+
|
163
|
+
gyoretsu.append(a[np.where(a[:,0]== ID1 ),np.where(a[0,:]== ID2)])
|
164
|
+
|
165
|
+
elif((np.any(a[0,:]== ID1) and np.any(a[:,0]==ID2))):
|
166
|
+
|
167
|
+
gyoretsu.append(a[np.where(a[0:,]== ID1),np.where(a[:,0]== ID2)])
|
168
|
+
|
169
|
+
else:
|
170
|
+
|
171
|
+
gyoretsu.append(0)
|
172
|
+
|
173
|
+
return gyoretsu
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
append_line = gyoretsu(line[4],line[5])
|
178
|
+
|
179
|
+
if(sum(append_line) != 0):
|
180
|
+
|
181
|
+
csvWriter.writerow(line + append_line)
|
182
|
+
|
183
|
+
df_new.close()
|
184
|
+
|
185
|
+
```
|
186
|
+
|
187
|
+
### エラーメッセージ
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
if((np.any(a[:,0]== ID1) and np.any(a[0,:]== ID2))):
|
192
|
+
|
193
|
+
NameError: name 'a' is not defined
|
194
|
+
|
195
|
+
```
|
196
|
+
|
71
|
-
|
197
|
+
コードは出来たんですが、エラーの対処法が分かりません。
|
72
|
-
|
198
|
+
|
73
|
-
|
199
|
+
aは定義出来ている気がするんですが…
|
74
200
|
|
75
201
|
### 補足情報(FW/ツールのバージョンなど)
|
76
202
|
|