【问题标题】:Plotting a time series with distinctive events in python在 python 中绘制具有独特事件的时间序列
【发布时间】:2018-07-20 05:45:15
【问题描述】:

我是数据新手。并且想知道最简单的方法是绘制我的数据:

我有一个看起来像这样的 pd.dataframe:

df.head()
    price     event
1   123
2   456       A
3   789
...

我想要一个时间序列,就像我一样

df.plot(x='price')

但是对于我的 DataFrame 中的每个条目,我的“事件”列等于某个值。

我最好的选择是什么?

谢谢。

【问题讨论】:

标签: python pandas matplotlib seaborn


【解决方案1】:

我冒昧地在事件 z 中添加了一行。

fig = plt.figure()
ax = fig.add_subplot(111)
x = df.reset_index()['index']
y = df['price']
ax.scatter(x, y)
ax.plot(y)
for i, txt in enumerate(df['event']):
    ax.annotate(txt, (x[i]+0.1,y[i]))

输出:

【讨论】:

    猜你喜欢
    • 2018-05-15
    • 2020-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-20
    • 1970-01-01
    • 2018-11-18
    • 1970-01-01
    相关资源
    最近更新 更多