/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2896 casted_key = self._maybe_cast_indexer(key)
2897 try:
-> 2898 return self._engine.get_loc(casted_key)
2899 except KeyError as err:
2900 raise KeyError(key) from err
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
TypeError: '(slice(0, 7, None), slice(None, -1, None))' is an invalid key
RNN 계열의 Time Series 딥러닝을 하다보면 발생하는 문제입니다.
저도 이거해결하느라 삽질을 좀 많이했는데요.. 원인은 이렇습니다.
Pandas df(dataframe)으로 불러온 데이터는 element들에 접근할시 x[0:1] 형태보다 x.iloc[0:1]의 형태를 고수해주어야합니다.
물론, x[0:1] 이런식으로도 접근은 할 수 있지만, 상기와 같은 pandas 접근에러가 뜰때는 정석으로 iloc을 붙여주는걸 추천드립니다.
#Data Windowing
def sliding_window(time_series, seq_length):
dataX = []
dataY = []
for i in range(0, len(time_series) - seq_length):
print(i)
_x = time_series.iloc[i:i + seq_length, : -1 ]
_y = time_series.iloc[i + seq_length, [-1]]
print(_x, "->", _y)
dataX.append(_x)
dataY.append(_y)
return np.array(dataX), np.array(dataY)
trainX, trainY = sliding_window(trainSet, seqLength)
testX, testY = sliding_window(testSet, seqLength)
[Errorcode]
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
TypeError: '(slice(None, None, None), slice(None, -1, None))' is an invalid key
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2896 casted_key = self._maybe_cast_indexer(key) 2897 try: -> 2898 return self._engine.get_loc(casted_key) 2899 except KeyError as err: 2900 raise KeyError(key) from err
'DeepLearning Framework & Coding > De-bugging' 카테고리의 다른 글
[python] AttributeError: 'numpy.ndarray' object has no attribute 'numpy' (0) | 2021.12.25 |
---|---|
[Github] Google Colab파일 Github로 push하기 (2) | 2021.12.21 |
cannot import name 'Adam' from 'keras.optimizers' (0) | 2021.09.06 |
ModuleNotFoundError: No module named 'wrapt' (0) | 2021.06.28 |
ImportError: cannot import name 'moduleTNC' from partially initialized module 'scipy.optimize' (0) | 2021.06.28 |
댓글