Simply using the example of the documentation:
Code Sample, a copy-pastable example if possible
ts = ps.Series(np.random.randn(1000), index=ps.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.plot()
Problem description
fails with the error: TypeError: float() argument must be a string or a number
Note: I confirmed that downgrading to Pandas version 0.19.0 this issue goes away.
Expected Output
I would expect a nicely formatted graph with date labels on the x-axis.
traceback
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-0d06e21bb979> in <module>()
2 ap.columns = [["Month", "Passengers"]]
3 apts = ps.Series(ap.Passengers.values.astype('float'), index=ap.Month)
----> 4 ax = apts.plot(marker='.', label='Airline Passengers')
5 ax.legend()
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pandas/tools/plotting.pyc 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)
3597 colormap=colormap, table=table, yerr=yerr,
3598 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3599 **kwds)
3600 __call__.__doc__ = plot_series.__doc__
3601
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pandas/tools/plotting.pyc 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)
2671 yerr=yerr, xerr=xerr,
2672 label=label, secondary_y=secondary_y,
-> 2673 **kwds)
2674
2675
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2467 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2468
-> 2469 plot_obj.generate()
2470 plot_obj.draw()
2471 return plot_obj.result
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in generate(self)
1041 self._compute_plot_data()
1042 self._setup_subplots()
-> 1043 self._make_plot()
1044 self._add_table()
1045 self._make_legend()
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _make_plot(self)
1724 stacking_id=stacking_id,
1725 is_errorbar=is_errorbar,
-> 1726 **kwds)
1727 self._add_legend_handle(newlines[0], label, index=i)
1728
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _ts_plot(cls, ax, x, data, style, **kwds)
1762 ax._plot_data.append((data, cls._kind, kwds))
1763
-> 1764 lines = cls._plot(ax, data.index, data.values, style=style, **kwds)
1765 # set date formatter, locators and rescale limits
1766 format_dateaxis(ax, ax.freq)
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(cls, ax, x, y, style, column_num, stacking_id, **kwds)
1739 cls._initialize_stacker(ax, stacking_id, len(y))
1740 y_values = cls._get_stacked_values(ax, stacking_id, y, kwds['label'])
-> 1741 lines = MPLPlot._plot(ax, x, y_values, style=style, **kwds)
1742 cls._update_stacker(ax, stacking_id, y)
1743 return lines
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(cls, ax, x, y, style, is_errorbar, **kwds)
1359 else:
1360 args = (x, y)
-> 1361 return ax.plot(*args, **kwds)
1362
1363 def _get_index_name(self):
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
1817 warnings.warn(msg % (label_namer, func.__name__),
1818 RuntimeWarning, stacklevel=2)
-> 1819 return func(ax, *args, **kwargs)
1820 pre_doc = inner.__doc__
1821 if pre_doc is None:
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in plot(self, *args, **kwargs)
1381
1382 for line in self._get_lines(*args, **kwargs):
-> 1383 self.add_line(line)
1384 lines.append(line)
1385
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in add_line(self, line)
1701 line.set_clip_path(self.patch)
1702
-> 1703 self._update_line_limits(line)
1704 if not line.get_label():
1705 line.set_label('_line%d' % len(self.lines))
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _update_line_limits(self, line)
1723 Figures out the data limit of the given line, updating self.dataLim.
1724 """
-> 1725 path = line.get_path()
1726 if path.vertices.size == 0:
1727 return
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/matplotlib/lines.pyc in get_path(self)
936 """
937 if self._invalidy or self._invalidx:
--> 938 self.recache()
939 return self._path
940
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/matplotlib/lines.pyc in recache(self, always)
623 x = ma.asarray(xconv, np.float_).filled(np.nan)
624 else:
--> 625 x = np.asarray(xconv, np.float_)
626 x = x.ravel()
627 else:
/Users/willem/dev/ml/keras/mlpy/lib/python2.7/site-packages/numpy/core/numeric.pyc in asarray(a, dtype, order)
480
481 """
--> 482 return array(a, dtype, copy=False, order=order)
483
484 def asanyarray(a, dtype=None, order=None):
TypeError: float() argument must be a string or a number
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Darwin
OS-release: 16.1.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.19.1
nose: None
pip: 9.0.1
setuptools: 28.8.0
Cython: None
numpy: 1.11.2
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.3
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
Comment From: smartsystems4u
Looking at the traceback. I don't understand why Pandas resolves to a _plot() / MPLplot() rather than a ts_plot().
Comment From: jorisvandenbossche
@smartsystems4u The traceback you show is from another example (eg are you sure there "Month"
is a datetime?). Can you show an actual reproducible example with traceback?
I cannot reproduce it with the simple cumsum example.
Comment From: smartsystems4u
@jorisvandenbossche Thanks for checking my issue so quickly!
Sorry for overreacting. I can no longer reproduce this problem :(
When creating a new virtualenv to reproduce the issue, the problem went away. It must have been a problem with my environment/installation.
You can close this issue.
Comment From: sinhrks
Thx for the confirmation. closing.