Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

[Dúvida] Erro ao gerar o gráfico

Estou tentando gerar o gráfico da aula de estatísticas descritivas, entretanto ele sempre gera o mesmo erro:

%matplotlib inline
import matplotlib.pyplot as plt 
plt.rc('figure', figsize = (20, 10))
grupo_bairro['Valor'].mean().plot.bar(color = 'blue')
---------------------------------------------------------------------------
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-29-a11be28fc085> in <module>()
----> 1 grupo_bairro['Valor'].mean().plot.bar(color = 'blue')

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in bar(self, **kwds)
   2781         axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
   2782         """
-> 2783         return self(kind='bar', **kwds)
   2784 
   2785     def barh(self, **kwds):

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
   2739                            colormap=colormap, table=table, yerr=yerr,
   2740                            xerr=xerr, label=label, secondary_y=secondary_y,
-> 2741                            **kwds)
   2742     __call__.__doc__ = plot_series.__doc__
   2743 

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
   2000                  yerr=yerr, xerr=xerr,
   2001                  label=label, secondary_y=secondary_y,
-> 2002                  **kwds)
   2003 
   2004 

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
   1802         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   1803 
-> 1804     plot_obj.generate()
   1805     plot_obj.draw()
   1806     return plot_obj.result

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in generate(self)
    256     def generate(self):
    257         self._args_adjust()
--> 258         self._compute_plot_data()
    259         self._setup_subplots()
    260         self._make_plot()

~\Anaconda3\lib\site-packages\pandas\plotting\_core.py in _compute_plot_data(self)
    361                                                    "datetime",
    362                                                    "datetimetz",
--> 363                                                    "timedelta"])
    364 
    365         try:

~\Anaconda3\lib\site-packages\pandas\core\frame.py in select_dtypes(self, include, exclude)
   3075         # the "union" of the logic of case 1 and case 2:
   3076         # we get the included and excluded, and return their logical and
-> 3077         include_these = Series(not bool(include), index=self.columns)
   3078         exclude_these = Series(not bool(exclude), index=self.columns)
   3079 

~\Anaconda3\lib\site-packages\pandas\core\series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    273             else:
    274                 data = _sanitize_array(data, index, dtype, copy,
--> 275                                        raise_cast_failure=True)
    276 
    277                 data = SingleBlockManager(data, index, fastpath=True)

~\Anaconda3\lib\site-packages\pandas\core\series.py in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
   4147 
   4148             subarr = construct_1d_arraylike_from_scalar(
-> 4149                 value, len(index), dtype)
   4150 
   4151         else:

~\Anaconda3\lib\site-packages\pandas\core\dtypes\cast.py in construct_1d_arraylike_from_scalar(value, length, dtype)
   1199         if is_integer_dtype(dtype) and isna(value):
   1200             dtype = np.float64
-> 1201         subarr = np.empty(length, dtype=dtype)
   1202         subarr.fill(value)
   1203 

TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type
2 respostas
solução!

Atualizei o pandas e o numpy e o problema foi resolvido!

Olá, Thales, tudo bem?

Que bom que resolveu o problema e compartilhou conosco a sua solução. Isto ajuda a outros estudantes que possam passar por situações semelhantes a sua para que navegando no fórum encontrem como resolver!

Forte abraço e bons estudos!