绘制与熊猫属性错误的时间序列

时间:2015-02-07 07:11:17

标签: python python-2.7 pandas

我在绘制数据框时遇到问题。数据框如下所示:

                     0              1
0  2012-01-01 00:00:00  123900.776741
1  2012-01-01 00:00:05  123900.776741
2  2012-01-01 00:00:10  123900.776741
3  2012-01-01 00:00:15  123900.776741
4  2012-01-01 00:00:20  123900.776741
5  2012-01-01 00:00:25  124815.050322
6  2012-01-01 00:00:30  125702.149798
7  2012-01-01 00:00:35  126589.249274
8  2012-01-01 00:00:40  127476.348751
9  2012-01-01 00:00:45  128363.448227

请注意,时间以5秒为增量上升。

当我写:

for x in monitor1:
    dfs.append(pd.read_csv(x, header=None, comment='#'))
df=pd.concat(dfs,ignore_index=True)
df[0] = pd.to_datetime(df[0])

#dates=pd.date_range('2012-01-01', '2012-02-01', freq='5S')
#dates=dates[:-1]
df.columns = ['Time', 'Data']
df = df.set_index('Time')
plt.plot(df)

我明白了: AttributeError:'TimeSeriesFigure'对象没有属性'_seen'

1 个答案:

答案 0 :(得分:0)

很可能是因为你的时间列不是索引。

假设完全相同的数据帧,请尝试以下操作:

# Renaming the columns for more clarity
df.columns = ['Time', 'Data']
# setting Time as index
df = df.set_index('Time')
# Plotting
df['Data'].plot()