1
resposta

Criando um DataFrame (pandas) para armazenar as variáveis explicativas (X)

Quando tento criar um DataFrame (pandas) para armazenar as variáveis explicativas (X) retorna o seguinte erro.

X = dados[['log_Area', 'log_Dist_Praia', 'log_Dist_Farmacia']]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_54168/654664084.py in <module>
----> 1 X = dados[['log_Area', 'log_Dist_Praia', 'log_Dist_Farmacia']]

~\anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
   3462             if is_iterator(key):
   3463                 key = list(key)
-> 3464             indexer = self.loc._get_listlike_indexer(key, axis=1)[1]
   3465 
   3466         # take() does not accept boolean indexers

~\anaconda3\lib\site-packages\pandas\core\indexing.py in _get_listlike_indexer(self, key, axis)
   1312             keyarr, indexer, new_indexer = ax._reindex_non_unique(keyarr)
   1313 
-> 1314         self._validate_read_indexer(keyarr, indexer, axis)
   1315 
   1316         if needs_i8_conversion(ax.dtype) or isinstance(

~\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_read_indexer(self, key, indexer, axis)
   1372                 if use_interval_msg:
   1373                     key = list(key)
-> 1374                 raise KeyError(f"None of [{key}] are in the [{axis_name}]")
   1375 
   1376             not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())

KeyError: "None of [Index(['log_Area', 'log_Dist_Praia', 'log_Dist_Farmacia'], dtype='object')] are in the [columns]"
1 resposta

Oi Luanna,

O seu código não está incorreto. Para melhor te ajudar seria interessante que você compartilhasse o seu notebook. Você pode abrir ele no Colab e compartilhar por aqui mesmo.

Fico no aguardo e bons estudos