- This topic has 2 replies, 2 voices, and was last updated 3 years, 10 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
Home › Forums › Fórum Python para Finanças: Análise de Dados e Machine Learning › keyerror: ‘Date” no gráfico de linhas
Quando executo o código abaixo no gráfico de linhas , aparece o erro abaixo. No histograma e no boxplot não apareceu nenhum erro.
Podem me ajudar,?
Obrigado
acoes_df.plot(x = ‘Date’, figsize = (20,8), title = ‘Histórico de preços das ações’)
KeyError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3360 try:
-> 3361 return self._engine.get_loc(casted_key)
3362 except KeyError as err:
5 frames
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: ‘Date’
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3361 return self._engine.get_loc(casted_key)
3362 except KeyError as err:
-> 3363 raise KeyError(key) from err
3364
3365 if is_scalar(key) and isna(key) and not self.hasnans:
KeyError: ‘Date’
Já consegui corrigir.
Na verdade não é necessário o parametro x = ‘Date’. É só excluir pq ele entra como default.
Olá André, que bom que deu certo e obrigado por ter compartilhado a solução aqui no fórum 🙂
Fabio