実現したいこと
KeyError 消したい
前提
ipythonを使い、MNISTのデータを読み込み、内容の確認をしたいです
ここで、データを変数に格納するところまでできました。
その後、任意のデータを取り出し、
test_number=X[53238]
と別変数に渡すところでKeyErrorが出ます。
発生している問題・エラーメッセージ
KeyError Traceback (most recent call last)
File C:\ProgramData\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3653, in Index.get_loc(self, key)
3652 try:
-> 3653 return self._engine.get_loc(casted_key)
3654 except KeyError as err:
File C:\ProgramData\anaconda3\lib\site-packages\pandas_libs\index.pyx:147, in pandas._libs.index.IndexEngine.get_loc()
File C:\ProgramData\anaconda3\lib\site-packages\pandas_libs\index.pyx:176, in pandas._libs.index.IndexEngine.get_loc()
File pandas_libs\hashtable_class_helper.pxi:7080, in pandas._libs.hashtable.PyObjectHashTable.get_item()
File pandas_libs\hashtable_class_helper.pxi:7088, in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 53238
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
Cell In[2], line 1
----> 1 test_number=X[53238]
File C:\ProgramData\anaconda3\lib\site-packages\pandas\core\frame.py:3761, in DataFrame.getitem(self, key)
3759 if self.columns.nlevels > 1:
3760 return self._getitem_multilevel(key)
-> 3761 indexer = self.columns.get_loc(key)
3762 if is_integer(indexer):
3763 indexer = [indexer]
File C:\ProgramData\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3655, in Index.get_loc(self, key)
3653 return self._engine.get_loc(casted_key)
3654 except KeyError as err:
-> 3655 raise KeyError(key) from err
3656 except TypeError:
3657 # If we have a listlike key, _check_indexing_error will raise
3658 # InvalidIndexError. Otherwise we fall through and re-raise
3659 # the TypeError.
3660 self._check_indexing_error(key)
KeyError: 53238
該当のソースコード
ipython
import os os.environ['KERAS_BACKEND'] = 'tensorflow' import keras as ks from keras.models import Sequential from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D from tensorflow.python.keras.utils import np_utils from sklearn.datasets import fetch_openml import pandas as pd import numpy as np import matplotlib import matplotlib.pyplot as plt mnist = fetch_openml('mnist_784',version=1,parser='auto') X, y = mnist['data'], mnist['target'] test_number = X[53238]
試したこと
関係するライブラリは、全てアップデートしました。
Pandasは、最新の2.0.3をインストールしました。
エラーは変わりませんでした。
回答1件
あなたの回答
tips
プレビュー