Skip to content

"ValueError: Could not get frequency alias for plotting" if DataFrame freq attr is None #2116

@willfurnass

Description

@willfurnass

The following was encountered when using Pandas 0.9.0 (specifically 0.9.0ppa6revno-3341~quantal1 from pythonxy PPA):

In [50]: df = pandas.read_csv("pandas_test.csv", parse_dates={'tstamp':[0,1]}, index_col='tstamp')

In [51]: df
Out[51]: 
                         flow
tstamp                       
2008-01-01 00:15:00  0.103906
2008-01-01 00:30:00  0.103906
2008-01-01 00:45:00  0.103906
2008-01-01 01:00:00  0.103906
2008-01-01 01:15:00  0.103906
2008-01-01 01:30:00  0.103906
2008-01-01 01:45:00  0.103906
2008-01-01 02:00:00  0.103906
2008-01-01 02:15:00  0.103594

In [5]: df.index
Out[5]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2008-01-01 00:15:00, ..., 2008-01-01 02:15:00]
Length: 9, Freq: None, Timezone: None

In [52]: df.plot()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-52-4f76bcc16520> in <module>()
----> 1 df.plot()

/usr/lib/pymodules/python2.7/pandas/tools/plotting.pyc in plot_frame(frame, x, y, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, style, title, xlim, ylim, logy, xticks, yticks, kind, sort_columns, fontsize, secondary_y, **kwds)
   1249                      sort_columns=sort_columns, secondary_y=secondary_y,
   1250                      **kwds)
-> 1251     plot_obj.generate()
   1252     plot_obj.draw()
   1253     if subplots:

/usr/lib/pymodules/python2.7/pandas/tools/plotting.pyc in generate(self)
    573         self._compute_plot_data()
    574         self._setup_subplots()
--> 575         self._make_plot()
    576         self._post_plot_logic()
    577         self._adorn_subplots()

/usr/lib/pymodules/python2.7/pandas/tools/plotting.pyc in _make_plot(self)
    880         # this is slightly deceptive
    881         if self.use_index and self._use_dynamic_x():
--> 882             data = self._maybe_convert_index(self.data)
    883             self._make_ts_plot(data, **self.kwds)
    884         else:

/usr/lib/pymodules/python2.7/pandas/tools/plotting.pyc in _maybe_convert_index(self, data)
   1022 
   1023             if freq is None:
-> 1024                 raise ValueError('Could not get frequency alias for plotting')
   1025 
   1026             data = DataFrame(data.values,

ValueError: Could not get frequency alias for plotting

However:

In [7]: df2 = df.resample("15min")

In [8]: df2.plot()
Out[8]: <matplotlib.axes.AxesSubplot at 0x4be91d0>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions