質問編集履歴
2
自分の解決策を考えたが、エラー発生
test
CHANGED
File without changes
|
test
CHANGED
@@ -209,3 +209,95 @@
|
|
209
209
|
|
210
210
|
|
211
211
|
とりあえず、条件の「T」と「F」の組み合わせから、期待値を取り出すのを一般化できればと思っています。
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
#自分の解決方法
|
216
|
+
|
217
|
+
自分の解決方法として、
|
218
|
+
|
219
|
+
例えば、実行結果の下の方の表で「電源ボタン」と「動作」が'T'でそれ以外が'F'だった時にexpected_valueの中の「電源ボタンを押す」という期待値をその列上に出したい。
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
プログラムとして、
|
224
|
+
|
225
|
+
・列と行をfor文で回していき、「電源ボタン」と「動作」が'T'だったらその場所の列の
|
226
|
+
|
227
|
+
位置(数値)を返す。
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
例は以下のコードで実現しようと考えている。
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
```python
|
236
|
+
|
237
|
+
expected_data = [[] for j in range(len(df.index))]
|
238
|
+
|
239
|
+
for index_number in range(len(df.index)):
|
240
|
+
|
241
|
+
for columns_number in range(len(df.columns)):
|
242
|
+
|
243
|
+
if df[columns_number][index_number] == 'T':
|
244
|
+
|
245
|
+
index_number += len(df.index) - 1
|
246
|
+
|
247
|
+
if df[columns_number][index_number] == 'T':
|
248
|
+
|
249
|
+
expected_data[index_number].append(columns_number)
|
250
|
+
|
251
|
+
print(expected_data)
|
252
|
+
|
253
|
+
```
|
254
|
+
|
255
|
+
#実行結果
|
256
|
+
|
257
|
+
Traceback (most recent call last):
|
258
|
+
|
259
|
+
File "C:\Anaconda\lib\site-packages\pandas\core\indexes\base.py", line 2428, in get_value
|
260
|
+
|
261
|
+
tz=getattr(series.dtype, 'tz', None))
|
262
|
+
|
263
|
+
File "pandas\_libs\index.pyx", line 98, in pandas._libs.index.IndexEngine.get_value (pandas\_libs\index.c:4363)
|
264
|
+
|
265
|
+
File "pandas\_libs\index.pyx", line 106, in pandas._libs.index.IndexEngine.get_value (pandas\_libs\index.c:4046)
|
266
|
+
|
267
|
+
File "pandas\_libs\index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5085)
|
268
|
+
|
269
|
+
File "pandas\_libs\hashtable_class_helper.pxi", line 1207, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20405)
|
270
|
+
|
271
|
+
File "pandas\_libs\hashtable_class_helper.pxi", line 1215, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20359)
|
272
|
+
|
273
|
+
KeyError: 4
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
During handling of the above exception, another exception occurred:
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
Traceback (most recent call last):
|
282
|
+
|
283
|
+
File "C:\atom\decision.py", line 72, in <module>
|
284
|
+
|
285
|
+
if df[columns_number][index_number] == 'T':
|
286
|
+
|
287
|
+
File "C:\Anaconda\lib\site-packages\pandas\core\series.py", line 601, in __getitem__
|
288
|
+
|
289
|
+
result = self.index.get_value(self, key)
|
290
|
+
|
291
|
+
File "C:\Anaconda\lib\site-packages\pandas\core\indexes\base.py", line 2434, in get_value
|
292
|
+
|
293
|
+
return libts.get_value_box(s, key)
|
294
|
+
|
295
|
+
File "pandas\_libs\tslib.pyx", line 923, in pandas._libs.tslib.get_value_box (pandas\_libs\tslib.c:18843)
|
296
|
+
|
297
|
+
File "pandas\_libs\tslib.pyx", line 939, in pandas._libs.tslib.get_value_box (pandas\_libs\tslib.c:18560)
|
298
|
+
|
299
|
+
IndexError: index out of bounds
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
実行結果はエラーが出ているので、教えてほしいと思っています。
|
1
少し内容を補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,6 +78,16 @@
|
|
78
78
|
|
79
79
|
のように対応させて表として表示させたい。
|
80
80
|
|
81
|
+
残りの条件も
|
82
|
+
|
83
|
+
・「ビデオボタン」と「動作」
|
84
|
+
|
85
|
+
・「静止ボタン」と「動作」
|
86
|
+
|
87
|
+
と対応している。
|
88
|
+
|
89
|
+
|
90
|
+
|
81
91
|
出来れば、条件や期待値が変わっても対応できるように一般化したい。
|
82
92
|
|
83
93
|
|
@@ -86,6 +96,8 @@
|
|
86
96
|
|
87
97
|
条件を与えて、真偽を網羅的に表示するところまでを行った。
|
88
98
|
|
99
|
+
コードは下記の通り。
|
100
|
+
|
89
101
|
```python
|
90
102
|
|
91
103
|
#表側,表頭を指定して、それに対応した期待値を抽出
|
@@ -191,3 +203,9 @@
|
|
191
203
|
```
|
192
204
|
|
193
205
|
長々と申し訳ありませんが、よろしくお願いします。
|
206
|
+
|
207
|
+
上記のコードにあるクラスなどは無視しても構いません。
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
とりあえず、条件の「T」と「F」の組み合わせから、期待値を取り出すのを一般化できればと思っています。
|