Código Inválido no Anaconda – Geração de Gráficos

Home Fóruns Fórum Python para Finanças: Análise de Dados e Machine Learning Código Inválido no Anaconda – Geração de Gráficos

Visualizando 2 posts - 1 até 2 (de 2 do total)
  • Autor
    Posts
  • #23394
    dougtaleb
    Participante

      Olá, professor

      Tinha aberto anteriormente uma dúvida referente a um erro de código na geração de histograma e assistindo a aula, eu vou testando o código, como foi o caso da minha dúvida anterior: eu escrevi o código conforme estava no documento de apoio no Jupyter, deu erro, logo reportei; porém como tenho muito azar, fui assistindo a aula e antes de reportar um erro, esperei até o final para reportar todos de uma vez só.

      Na aula em questão, houveram 7 códigos para gerar gráficos, tive problema com 5, que foram:

       

      1º – ”  sns.histplot(acoes_df[‘GOL’]);

      —————————————————————————
      AttributeError Traceback (most recent call last)
      <ipython-input-57-609f3eb789cb> in <module>
      —-> 1 sns.histplot(acoes_df[‘GOL’]);

      AttributeError: module ‘seaborn’ has no attribute ‘histplot’ ”

       

      2º – ” plt.figure(figsize=(10,50))
      i = 1
      for i in np.arange(1, len(acoes_df.columns)):
      plt.subplot(7, 1, i + 1)
      sns.histplot(acoes_df[acoes_df.columns[i]], kde = True)
      plt.title(acoes_df.columns[i])

       

      —————————————————————————
      AttributeError Traceback (most recent call last)
      <ipython-input-26-89558c40eb6d> in <module>
      3 for i in np.arange(1, len(acoes_df.columns)):
      4 plt.subplot(7, 1, i + 1)
      —-> 5 sns.histplot(acoes_df[acoes_df.columns[i]], kde = True)
      6 plt.title(acoes_df.columns[i])

      AttributeError: module ‘seaborn’ has no attribute ‘histplot’

       

      3º – ” acoes_df.plot(x = ‘Date’, figsize = (15,7), title = ‘Histórico do preço das ações’);

      —————————————————————————
      KeyError Traceback (most recent call last)
      ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
      2645 try:
      -> 2646 return self._engine.get_loc(key)
      2647 except KeyError:

      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’

      During handling of the above exception, another exception occurred:

      KeyError Traceback (most recent call last)
      <ipython-input-31-9a21a808212d> in <module>
      —-> 1 acoes_df.plot(x = ‘Date’, figsize = (15,7), title = ‘Histórico do preço das ações’);

      ~\anaconda3\lib\site-packages\pandas\plotting\_core.py in __call__(self, *args, **kwargs)
      810 if is_integer(x) and not data.columns.holds_integer():
      811 x = data_cols[x]
      –> 812 elif not isinstance(data[x], ABCSeries):
      813 raise ValueError(“x must be a label or position”)
      814 data = data.set_index(x)

      ~\anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
      2798 if self.columns.nlevels > 1:
      2799 return self._getitem_multilevel(key)
      -> 2800 indexer = self.columns.get_loc(key)
      2801 if is_integer(indexer):
      2802 indexer = [indexer]

      ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
      2646 return self._engine.get_loc(key)
      2647 except KeyError:
      -> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
      2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
      2650 if indexer.ndim > 1 or indexer.size > 1:

      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’ ”

       

      4º – ” acoes_df_normalizado.plot(x=’Date’,figsize = (15,7),title=’Histórico do preço das ações – normalizado’);

      —————————————————————————
      KeyError Traceback (most recent call last)
      ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
      2645 try:
      -> 2646 return self._engine.get_loc(key)
      2647 except KeyError:

      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’

      During handling of the above exception, another exception occurred:

      KeyError Traceback (most recent call last)
      <ipython-input-43-359e24811c03> in <module>
      —-> 1 acoes_df_normalizado.plot(x=’Date’,figsize = (15,7),title=’Histórico do preço das ações – normalizado’);

      ~\anaconda3\lib\site-packages\pandas\plotting\_core.py in __call__(self, *args, **kwargs)
      810 if is_integer(x) and not data.columns.holds_integer():
      811 x = data_cols[x]
      –> 812 elif not isinstance(data[x], ABCSeries):
      813 raise ValueError(“x must be a label or position”)
      814 data = data.set_index(x)

      ~\anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
      2798 if self.columns.nlevels > 1:
      2799 return self._getitem_multilevel(key)
      -> 2800 indexer = self.columns.get_loc(key)
      2801 if is_integer(indexer):
      2802 indexer = [indexer]

      ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
      2646 return self._engine.get_loc(key)
      2647 except KeyError:
      -> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
      2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
      2650 if indexer.ndim > 1 or indexer.size > 1:

      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’ ”

       

      5º – ” figura = px.line(title = ‘Histórico do preço das ações’)
      for i in acoes_df.columns[1:]:
      figura.add_scatter(x = acoes_df[‘Date’], y = acoes_df[i], name = i)
      figura.show()

      —————————————————————————
      KeyError Traceback (most recent call last)
      ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
      2645 try:
      -> 2646 return self._engine.get_loc(key)
      2647 except KeyError:

      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’

      During handling of the above exception, another exception occurred:

      KeyError Traceback (most recent call last)
      <ipython-input-40-c27103b88088> in <module>
      1 figura = px.line(title = ‘Histórico do preço das ações’)
      2 for i in acoes_df.columns[1:]:
      —-> 3 figura.add_scatter(x = acoes_df[‘Date’], y = acoes_df[i], name = i)
      4 figura.show()

      ~\anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
      2798 if self.columns.nlevels > 1:
      2799 return self._getitem_multilevel(key)
      -> 2800 indexer = self.columns.get_loc(key)
      2801 if is_integer(indexer):
      2802 indexer = [indexer]

      ~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
      2646 return self._engine.get_loc(key)
      2647 except KeyError:
      -> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
      2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
      2650 if indexer.ndim > 1 or indexer.size > 1:

      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’ ”

       

      Foram esses os erros, não sei se fiz algo de errado; mas os códigos:

      sns.boxplot(x = acoes_df[‘GOL’]);

      e

      plt.figure(figsize=(10,50))
      i = 1
      for i in np.arange(1, len(acoes_df.columns)):
      plt.subplot(7, 1, i + 1)
      sns.boxplot(x = acoes_df[acoes_df.columns[i]])
      plt.title(acoes_df.columns[i])

      foi sem problemas. Poderia me auxiliar, por gentileza?

       

      #23413
      Fábio Spak
      Participante

        Boa tarde dougtaleb, respondi na outra pergunta, aguardo seus testes.

        Fabio

      Visualizando 2 posts - 1 até 2 (de 2 do total)
      • Você deve fazer login para responder a este tópico.