pd.version == 0.19.0
I have two DataFrames which have the same index types, dtypes & columns. For some reason, the first DataFrame plots while the second does not. However, when I store them as .csv's and read them back in again, the problem is solved.
I suspect it has something to do with the columnar index or the DateTime index. Since saving them as .csv files wouldn't capture the issue I'm having, I saved them as .pkl files and zipped them below.
Finally, to replicate the issue, I ran a.plot()
and b.plot()
. Upon running b.plot()
I get:
Traceback (most recent call last):
File "<ipython-input-507-904a8054cbcc>", line 1, in <module>
b.plot()
File "/.../site-packages/pandas/tools/plotting.py", line 3773, in __call__
sort_columns=sort_columns, **kwds)
File "/.../site-packages/pandas/tools/plotting.py", line 2642, in plot_frame
**kwds)
File "/.../site-packages/pandas/tools/plotting.py", line 2469, in _plot
plot_obj.generate()
File "/.../site-packages/pandas/tools/plotting.py", line 1043, in generate
self._make_plot()
File "/.../site-packages/pandas/tools/plotting.py", line 1698, in _make_plot
data = _maybe_convert_index(self._get_ax(0), self.data)
File "/.../site-packages/pandas/tseries/plotting.py", line 255, in _maybe_convert_index
data = data.to_period(freq=freq)
File "/.../site-packages/pandas/core/frame.py", line 5224, in to_period
new_data.set_axis(1, self.index.to_period(freq=freq))
File "/.../site-packages/pandas/tseries/index.py", line 928, in to_period
return PeriodIndex(self.values, name=self.name, freq=freq, tz=self.tz)
File "/.../site-packages/pandas/tseries/period.py", line 213, in __new__
ordinal, freq = cls._from_arraylike(data, freq, tz)
File "/.../site-packages/pandas/tseries/period.py", line 292, in _from_arraylike
data = dt64arr_to_periodarr(data, freq, tz)
File "/.../site-packages/pandas/tseries/period.py", line 62, in dt64arr_to_periodarr
base, mult = _gfc(freq)
File "/.../site-packages/pandas/tseries/frequencies.py", line 282, in get_freq_code
base, stride = _base_and_stride(freqstr)
File "/.../site-packages/pandas/tseries/frequencies.py", line 507, in _base_and_stride
groups = opattern.match(freqstr)
TypeError: expected string or buffer
Update: the issue seems to disappear when I reassign the index with b.index = b.index.map(str)
; that is, I drop the datetime datatype.
Comment From: ischurov
Could you reproduce it on pandas v. 0.19.1 or later? I tried on 0.19.1 and current master and it works for me.
import pandas as pd
a = pd.read_pickle("a.pkl")
b = pd.read_pickle("b.pkl")
a.plot()
# get picture
b.plot()
# get picture
Comment From: jorisvandenbossche
@alexpetralia can you try with the latest release?
Comment From: alexpetralia
Yep, I just tried with 0.19.2 and it is resolved. Thanks!
Comment From: jorisvandenbossche
@alexpetralia Thanks for testing!