答案 0 :(得分:2)
假设我们有以下DF:
In [159]: df
Out[159]:
2014-02-12 2014-02-13 2014-02-14
00:00 19.74 24.76 24.83
00:15 20.21 25.41 19.19
让我们创建一个助手DF:
In [160]: x = df.T.stack().reset_index(name='val')
In [161]: x
Out[161]:
level_0 level_1 val
0 2014-02-12 00:00 19.74
1 2014-02-12 00:15 20.21
2 2014-02-13 00:00 24.76
3 2014-02-13 00:15 25.41
4 2014-02-14 00:00 24.83
5 2014-02-14 00:15 19.19
In [162]: x['Date'] = pd.to_datetime(x.pop('level_0') + ' ' + x.pop('level_1'))
In [163]: x
Out[163]:
val Date
0 19.74 2014-02-12 00:00:00
1 20.21 2014-02-12 00:15:00
2 24.76 2014-02-13 00:00:00
3 25.41 2014-02-13 00:15:00
4 24.83 2014-02-14 00:00:00
5 19.19 2014-02-14 00:15:00
现在我们可以很容易地绘制它:
In [165]: import matplotlib
...: matplotlib.style.use('ggplot')
...:
In [166]: x.plot(x='Date', y='val')
Out[166]: <matplotlib.axes._subplots.AxesSubplot at 0xc03ce10>