|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #合并训练集和测试集
- #train_dataset.drop(['Id','SalePrice'],axis=1)
- full_dataset = pd.concat([train_dataset.drop(['Id','SalePrice'],axis=1),test_dataset[:,1:]])
- #train_dataset.shape,test_dataset.shape,full_dataset.shape
复制代码
报错如下- ---------------------------------------------------------------------------
- TypeError Traceback (most recent call last)
- File /opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py:3805, in Index.get_loc(self, key)
- 3804 try:
- -> 3805 return self._engine.get_loc(casted_key)
- 3806 except KeyError as err:
- File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()
- File index.pyx:173, in pandas._libs.index.IndexEngine.get_loc()
- TypeError: '(slice(None, None, None), slice(1, None, None))' is an invalid key
- During handling of the above exception, another exception occurred:
- InvalidIndexError Traceback (most recent call last)
- Cell In[58], line 3
- 1 #合并训练集和测试集
- 2 #train_dataset.drop(['Id','SalePrice'],axis=1)
- ----> 3 full_dataset = pd.concat([train_dataset.drop(['Id','SalePrice'],axis=1),test_dataset[:,1:]])
- 4 #train_dataset.shape,test_dataset.shape,full_dataset.shape
- File /opt/conda/lib/python3.10/site-packages/pandas/core/frame.py:4102, in DataFrame.__getitem__(self, key)
- 4100 if self.columns.nlevels > 1:
- 4101 return self._getitem_multilevel(key)
- -> 4102 indexer = self.columns.get_loc(key)
- 4103 if is_integer(indexer):
- 4104 indexer = [indexer]
- File /opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py:3817, in Index.get_loc(self, key)
- 3812 raise KeyError(key) from err
- 3813 except TypeError:
- 3814 # If we have a listlike key, _check_indexing_error will raise
- 3815 # InvalidIndexError. Otherwise we fall through and re-raise
- 3816 # the TypeError.
- -> 3817 self._check_indexing_error(key)
- 3818 raise
- File /opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py:6059, in Index._check_indexing_error(self, key)
- 6055 def _check_indexing_error(self, key):
- 6056 if not is_scalar(key):
- 6057 # if key is not a scalar, directly raise an error (the code below
- 6058 # would convert to numpy arrays and raise later any way) - GH29926
- -> 6059 raise InvalidIndexError(key)
- InvalidIndexError: (slice(None, None, None), slice(1, None, None))
复制代码 |
|