erro na aula com Gráficos de limha

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27840
    pereira
    Participant

      acoes_df.plot(x = ‘Date’, figsize = (15,7), title = ‘Histórico do preço 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)
      2897 try:
      -> 2898 return self._engine.get_loc(casted_key)
      2899 except KeyError as err:

      pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

      pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

      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)

      3 frames
      /usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
      2898 return self._engine.get_loc(casted_key)
      2899 except KeyError as err:
      -> 2900 raise KeyError(key) from err
      2901
      2902 if tolerance is not None:

       

      #27927
      Fábio Spak
      Participant

        Boa tarde pereira, consegue verificar se o nome do parâmetro “Date” esta correto?

        Fabio

        #31799
        Pras
        Participant

          Erro no parâmetro  “Date”

           

          acoes_df.plot(x= ‘Date’,  figsize = (15,7),  title= ‘ Historico de preços de 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)
          2897 try:
          -> 2898 return self._engine.get_loc(casted_key)
          2899 except KeyError as err:

          pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

          pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

          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)

          3 frames
          /usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
          2898 return self._engine.get_loc(casted_key)
          2899 except KeyError as err:
          -> 2900 raise KeyError(key) from err
          2901
          2902 if tolerance is not None:

          KeyError: ‘Date’

           

          #44790
          Denny Ceccon
          Moderator

            Provavelmente Date está sendo utilizado como índice do dataframe, você pode resolver isso fazendo:

            acoes_df.reset_index(drop=False, inplace=True)
            
            

            Assim Date passa a ser uma coluna e a função funciona.

          Viewing 4 posts - 1 through 4 (of 4 total)
          • You must be logged in to reply to this topic.