绘制DataFrame时出现以下错误。我会尝试最低限度地复制它......我猜测索引是以某种方式从index.drop调用搞砸了。在这一点上,这似乎是一个错误。
更新:此代码重现我的设置错误(python 3.3.2)
import pandas
from pylab import *
print('pandas version', pandas.__version__)
df = pandas.DataFrame(randn(6,2))
df.index = pandas.Index(['2013-05-03 00:00:00', '2013-05-01 00:00:00', '2013-05-01 00:00:00', '2013-05-02 00:00:00', '2013-05-06 00:00:00', '2013-05-07 00:00:00'], dtype=object)
# this one passes!?
# df = pandas.DataFrame(randn(5,2))
# df.index = pandas.Index(['2013-05-01 00:00:00', '2013-05-01 00:00:00', '2013-05-02 00:00:00', '2013-05-06 00:00:00', '2013-05-07 00:00:00'], dtype=object)
print(df.shape)
print(df)
df.index = [pandas.datetools.parse(x) for x in df.index]
print(df.shape)
print(df)
try:
df.plot()
print('first df.plot() passed')
except Exception as e:
print('Caught Exception on df.plot()', e)
df = df.sort_index()
print(df.shape)
print(df)
df.plot()
print('df.plot() works after df.sort_index()')
结果:
$ python3 p.py
pandas version 0.12.0
(6, 2)
0 1
2013-05-03 00:00:00 0.049095 0.199115
2013-05-01 00:00:00 -0.637439 0.201922
2013-05-01 00:00:00 -1.441205 -0.006792
2013-05-02 00:00:00 1.673248 1.558569
2013-05-06 00:00:00 -0.168974 0.457340
2013-05-07 00:00:00 -0.165104 -1.642641
(6, 2)
0 1
2013-05-03 0.049095 0.199115
2013-05-01 -0.637439 0.201922
2013-05-01 -1.441205 -0.006792
2013-05-02 1.673248 1.558569
2013-05-06 -0.168974 0.457340
2013-05-07 -0.165104 -1.642641
Caught Exception on df.plot() Shape of passed values is (2, 8), indices imply (2, 6)
(6, 2)
0 1
2013-05-01 -0.637439 0.201922
2013-05-01 -1.441205 -0.006792
2013-05-02 1.673248 1.558569
2013-05-03 0.049095 0.199115
2013-05-06 -0.168974 0.457340
2013-05-07 -0.165104 -1.642641
df.plot() works after df.sort_index()