'I have a problem when I try run a matplotlib command in Python

I have a dataset in python, that is operating is ok, but when I try visualize in matplotlib continuously get a mistake.

I type a viz.plot() command and this is:

This message is.:

TypeError                                 Traceback (most recent call last)
<ipython-input-18-7608c70ebd6e> in <module>
----> 1 viz.plot()

/usr/lib/python3/dist-packages/pandas/plotting/_core.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   2939                           fontsize=fontsize, colormap=colormap, table=table,
   2940                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2941                           sort_columns=sort_columns, **kwds)
   2942     __call__.__doc__ = plot_frame.__doc__
   2943 

/usr/lib/python3/dist-packages/pandas/plotting/_core.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   1975                  yerr=yerr, xerr=xerr,
   1976                  secondary_y=secondary_y, sort_columns=sort_columns,
-> 1977                  **kwds)
   1978 
   1979 

/usr/lib/python3/dist-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

/usr/lib/python3/dist-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()

/usr/lib/python3/dist-packages/pandas/plotting/_core.py in _compute_plot_data(self)
    361                                                    "datetime",
    362                                                    "datetimetz",
--> 363                                                    "timedelta"])
    364 
    365         try:

/usr/lib/python3/dist-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 

/usr/lib/python3/dist-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)

/usr/lib/python3/dist-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:

/usr/lib/python3/dist-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

Does anyone know what the solution might be?? Thank you very much in advance for your response.: Gabor-Gabor



Solution 1:[1]

I suppose "viz" is your dataframe. To make use of plot() you need to give 2 parameters: plt.plot(x,y) or plt.plot(x,y,viz)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 josue david castillo araiza