質問編集履歴
2
エラー解決(行指定エラー)のため、更新しておきます。
test
CHANGED
File without changes
|
test
CHANGED
@@ -91,231 +91,3 @@
|
|
91
91
|
|
92
92
|
|
93
93
|
別テーブルの条件(x1, x2, y1, y2)を参照し、データテーブルのx, yがそのうちどの区間に入っているか判別、対応するarea列の値を返す、ことをしたいです。
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
### 【追記】発生している問題・エラーメッセージ
|
98
|
-
|
99
|
-
以下プログラムを実行しましたが、エラーがでて処理が完了しません。
|
100
|
-
|
101
|
-
test_datav03の21列目に、反映結果のデータを入れたいと考えています。
|
102
|
-
|
103
|
-
list_test.csvが定義テーブルのデータです。
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
```Python
|
108
|
-
|
109
|
-
import numpy as np
|
110
|
-
|
111
|
-
import pandas as pd
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
#csvを読み込み
|
116
|
-
|
117
|
-
df = pd.read_csv("testdata_v03.csv", header=0)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
print(df)
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
df_ref = pd.read_csv("list_test.csv", header=0)
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
df.T.apply(lambda x: ','.join(df_ref[(df_ref.values[:, 1] <= x.values[9]) &
|
130
|
-
|
131
|
-
(df_ref.values[:, 2] >= x.values[9]) &
|
132
|
-
|
133
|
-
(df_ref.values[:, 3] <= x.values[10]) &
|
134
|
-
|
135
|
-
(df_ref.values[:, 4] >= x.values[10])].iloc[:, 21].values.astype(str)))
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
print(df)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
```
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
以下エラーがでています。
|
148
|
-
|
149
|
-
---------------------------------------------------------------------------
|
150
|
-
|
151
|
-
IndexError Traceback (most recent call last)
|
152
|
-
|
153
|
-
<ipython-input-3-4a0b1b44785f> in <module>()
|
154
|
-
|
155
|
-
9 df_ref = pd.read_csv("area_list_test.csv", header=0)
|
156
|
-
|
157
|
-
10
|
158
|
-
|
159
|
-
---> 11 df.T.apply(lambda x: ','.join(df_ref[(df_ref.values[:, 1] <= x.values[9]) &
|
160
|
-
|
161
|
-
12 (df_ref.values[:, 2] >= x.values[9]) &
|
162
|
-
|
163
|
-
13 (df_ref.values[:, 3] <= x.values[10]) &
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\frame.py in apply(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds)
|
168
|
-
|
169
|
-
6012 args=args,
|
170
|
-
|
171
|
-
6013 kwds=kwds)
|
172
|
-
|
173
|
-
-> 6014 return op.get_result()
|
174
|
-
|
175
|
-
6015
|
176
|
-
|
177
|
-
6016 def applymap(self, func):
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in get_result(self)
|
182
|
-
|
183
|
-
316 *self.args, **self.kwds)
|
184
|
-
|
185
|
-
317
|
186
|
-
|
187
|
-
--> 318 return super(FrameRowApply, self).get_result()
|
188
|
-
|
189
|
-
319
|
190
|
-
|
191
|
-
320 def apply_broadcast(self):
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in get_result(self)
|
196
|
-
|
197
|
-
140 return self.apply_raw()
|
198
|
-
|
199
|
-
141
|
200
|
-
|
201
|
-
--> 142 return self.apply_standard()
|
202
|
-
|
203
|
-
143
|
204
|
-
|
205
|
-
144 def apply_empty_result(self):
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in apply_standard(self)
|
210
|
-
|
211
|
-
246
|
212
|
-
|
213
|
-
247 # compute the result using the series generator
|
214
|
-
|
215
|
-
--> 248 self.apply_series_generator()
|
216
|
-
|
217
|
-
249
|
218
|
-
|
219
|
-
250 # wrap results
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in apply_series_generator(self)
|
224
|
-
|
225
|
-
275 try:
|
226
|
-
|
227
|
-
276 for i, v in enumerate(series_gen):
|
228
|
-
|
229
|
-
--> 277 results[i] = self.f(v)
|
230
|
-
|
231
|
-
278 keys.append(v.name)
|
232
|
-
|
233
|
-
279 except Exception as e:
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
<ipython-input-3-4a0b1b44785f> in <lambda>(x)
|
238
|
-
|
239
|
-
12 (df_ref.values[:, 2] >= x.values[9]) &
|
240
|
-
|
241
|
-
13 (df_ref.values[:, 3] <= x.values[10]) &
|
242
|
-
|
243
|
-
---> 14 (df_ref.values[:, 4] >= x.values[10])].iloc[:, 21].values.astype(str)))
|
244
|
-
|
245
|
-
15
|
246
|
-
|
247
|
-
16 print(df)
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
|
252
|
-
|
253
|
-
1470 except (KeyError, IndexError):
|
254
|
-
|
255
|
-
1471 pass
|
256
|
-
|
257
|
-
-> 1472 return self._getitem_tuple(key)
|
258
|
-
|
259
|
-
1473 else:
|
260
|
-
|
261
|
-
1474 # we by definition only have the 0th axis
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_tuple(self, tup)
|
266
|
-
|
267
|
-
2011 def _getitem_tuple(self, tup):
|
268
|
-
|
269
|
-
2012
|
270
|
-
|
271
|
-
-> 2013 self._has_valid_tuple(tup)
|
272
|
-
|
273
|
-
2014 try:
|
274
|
-
|
275
|
-
2015 return self._getitem_lowerdim(tup)
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _has_valid_tuple(self, key)
|
280
|
-
|
281
|
-
220 raise IndexingError('Too many indexers')
|
282
|
-
|
283
|
-
221 try:
|
284
|
-
|
285
|
-
--> 222 self._validate_key(k, i)
|
286
|
-
|
287
|
-
223 except ValueError:
|
288
|
-
|
289
|
-
224 raise ValueError("Location based indexing can only have "
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_key(self, key, axis)
|
294
|
-
|
295
|
-
1955 return
|
296
|
-
|
297
|
-
1956 elif is_integer(key):
|
298
|
-
|
299
|
-
-> 1957 self._validate_integer(key, axis)
|
300
|
-
|
301
|
-
1958 elif isinstance(key, tuple):
|
302
|
-
|
303
|
-
1959 # a tuple should already have been caught by this point
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_integer(self, key, axis)
|
308
|
-
|
309
|
-
2007 l = len(ax)
|
310
|
-
|
311
|
-
2008 if key >= l or key < -l:
|
312
|
-
|
313
|
-
-> 2009 raise IndexError("single positional indexer is out-of-bounds")
|
314
|
-
|
315
|
-
2010
|
316
|
-
|
317
|
-
2011 def _getitem_tuple(self, tup):
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
IndexError: ('single positional indexer is out-of-bounds', 'occurred at index 0')
|
1
プログラムを実際のテストファイルで実装したところ、エラーがでたため、その部分を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -86,8 +86,236 @@
|
|
86
86
|
|
87
87
|
|
88
88
|
|
89
|
-
###
|
89
|
+
### 実施イメージ
|
90
90
|
|
91
91
|
|
92
92
|
|
93
93
|
別テーブルの条件(x1, x2, y1, y2)を参照し、データテーブルのx, yがそのうちどの区間に入っているか判別、対応するarea列の値を返す、ことをしたいです。
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
### 【追記】発生している問題・エラーメッセージ
|
98
|
+
|
99
|
+
以下プログラムを実行しましたが、エラーがでて処理が完了しません。
|
100
|
+
|
101
|
+
test_datav03の21列目に、反映結果のデータを入れたいと考えています。
|
102
|
+
|
103
|
+
list_test.csvが定義テーブルのデータです。
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
```Python
|
108
|
+
|
109
|
+
import numpy as np
|
110
|
+
|
111
|
+
import pandas as pd
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
#csvを読み込み
|
116
|
+
|
117
|
+
df = pd.read_csv("testdata_v03.csv", header=0)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
print(df)
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
df_ref = pd.read_csv("list_test.csv", header=0)
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
df.T.apply(lambda x: ','.join(df_ref[(df_ref.values[:, 1] <= x.values[9]) &
|
130
|
+
|
131
|
+
(df_ref.values[:, 2] >= x.values[9]) &
|
132
|
+
|
133
|
+
(df_ref.values[:, 3] <= x.values[10]) &
|
134
|
+
|
135
|
+
(df_ref.values[:, 4] >= x.values[10])].iloc[:, 21].values.astype(str)))
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
print(df)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
以下エラーがでています。
|
148
|
+
|
149
|
+
---------------------------------------------------------------------------
|
150
|
+
|
151
|
+
IndexError Traceback (most recent call last)
|
152
|
+
|
153
|
+
<ipython-input-3-4a0b1b44785f> in <module>()
|
154
|
+
|
155
|
+
9 df_ref = pd.read_csv("area_list_test.csv", header=0)
|
156
|
+
|
157
|
+
10
|
158
|
+
|
159
|
+
---> 11 df.T.apply(lambda x: ','.join(df_ref[(df_ref.values[:, 1] <= x.values[9]) &
|
160
|
+
|
161
|
+
12 (df_ref.values[:, 2] >= x.values[9]) &
|
162
|
+
|
163
|
+
13 (df_ref.values[:, 3] <= x.values[10]) &
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\frame.py in apply(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds)
|
168
|
+
|
169
|
+
6012 args=args,
|
170
|
+
|
171
|
+
6013 kwds=kwds)
|
172
|
+
|
173
|
+
-> 6014 return op.get_result()
|
174
|
+
|
175
|
+
6015
|
176
|
+
|
177
|
+
6016 def applymap(self, func):
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in get_result(self)
|
182
|
+
|
183
|
+
316 *self.args, **self.kwds)
|
184
|
+
|
185
|
+
317
|
186
|
+
|
187
|
+
--> 318 return super(FrameRowApply, self).get_result()
|
188
|
+
|
189
|
+
319
|
190
|
+
|
191
|
+
320 def apply_broadcast(self):
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in get_result(self)
|
196
|
+
|
197
|
+
140 return self.apply_raw()
|
198
|
+
|
199
|
+
141
|
200
|
+
|
201
|
+
--> 142 return self.apply_standard()
|
202
|
+
|
203
|
+
143
|
204
|
+
|
205
|
+
144 def apply_empty_result(self):
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in apply_standard(self)
|
210
|
+
|
211
|
+
246
|
212
|
+
|
213
|
+
247 # compute the result using the series generator
|
214
|
+
|
215
|
+
--> 248 self.apply_series_generator()
|
216
|
+
|
217
|
+
249
|
218
|
+
|
219
|
+
250 # wrap results
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in apply_series_generator(self)
|
224
|
+
|
225
|
+
275 try:
|
226
|
+
|
227
|
+
276 for i, v in enumerate(series_gen):
|
228
|
+
|
229
|
+
--> 277 results[i] = self.f(v)
|
230
|
+
|
231
|
+
278 keys.append(v.name)
|
232
|
+
|
233
|
+
279 except Exception as e:
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
<ipython-input-3-4a0b1b44785f> in <lambda>(x)
|
238
|
+
|
239
|
+
12 (df_ref.values[:, 2] >= x.values[9]) &
|
240
|
+
|
241
|
+
13 (df_ref.values[:, 3] <= x.values[10]) &
|
242
|
+
|
243
|
+
---> 14 (df_ref.values[:, 4] >= x.values[10])].iloc[:, 21].values.astype(str)))
|
244
|
+
|
245
|
+
15
|
246
|
+
|
247
|
+
16 print(df)
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
|
252
|
+
|
253
|
+
1470 except (KeyError, IndexError):
|
254
|
+
|
255
|
+
1471 pass
|
256
|
+
|
257
|
+
-> 1472 return self._getitem_tuple(key)
|
258
|
+
|
259
|
+
1473 else:
|
260
|
+
|
261
|
+
1474 # we by definition only have the 0th axis
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_tuple(self, tup)
|
266
|
+
|
267
|
+
2011 def _getitem_tuple(self, tup):
|
268
|
+
|
269
|
+
2012
|
270
|
+
|
271
|
+
-> 2013 self._has_valid_tuple(tup)
|
272
|
+
|
273
|
+
2014 try:
|
274
|
+
|
275
|
+
2015 return self._getitem_lowerdim(tup)
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _has_valid_tuple(self, key)
|
280
|
+
|
281
|
+
220 raise IndexingError('Too many indexers')
|
282
|
+
|
283
|
+
221 try:
|
284
|
+
|
285
|
+
--> 222 self._validate_key(k, i)
|
286
|
+
|
287
|
+
223 except ValueError:
|
288
|
+
|
289
|
+
224 raise ValueError("Location based indexing can only have "
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_key(self, key, axis)
|
294
|
+
|
295
|
+
1955 return
|
296
|
+
|
297
|
+
1956 elif is_integer(key):
|
298
|
+
|
299
|
+
-> 1957 self._validate_integer(key, axis)
|
300
|
+
|
301
|
+
1958 elif isinstance(key, tuple):
|
302
|
+
|
303
|
+
1959 # a tuple should already have been caught by this point
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_integer(self, key, axis)
|
308
|
+
|
309
|
+
2007 l = len(ax)
|
310
|
+
|
311
|
+
2008 if key >= l or key < -l:
|
312
|
+
|
313
|
+
-> 2009 raise IndexError("single positional indexer is out-of-bounds")
|
314
|
+
|
315
|
+
2010
|
316
|
+
|
317
|
+
2011 def _getitem_tuple(self, tup):
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
IndexError: ('single positional indexer is out-of-bounds', 'occurred at index 0')
|