I am new to time-series programming with pandas. Can somebody help me with this.
Create a plot with x axis as timestamp and y axis as shifted price. In the plot draw the following dotted lines:
Green dotted line which indicates mean
Red dotted lines which indicates one standard deviation above and below x-axis.
Following is a sample image which shows the shifted price in y-axis, time in x-axis, green dotted line on mean and red dotted line on +- standard deviation
here is the sample data:
0 2017-11-05 09:20:01.134 2123.0 12.23 34.12 300.0
1 2017-11-05 09:20:01.789 2133.0 32.43 45.62 330.0
2 2017-11-05 09:20:02.238 2423.0 35.43 55.62 NaN
3 2017-11-05 09:20:02.567 3423.0 65.43 56.62 NaN
4 2017-11-05 09:20:02.948 2463.0 45.43 58.62 NaN
答案 0 :(得分:0)
将您的价格视为系列,并将其绘制如下:
import numpy as np
import pandas as pd
# Date
rng = pd.date_range('1/1/2000', periods=1000)
# Create a Random Series
ts = pd.Series(np.random.randn(len(rng)), index=rng)
# Create plot
ax = ts.plot()
# Plot de mean
ax.axhline(y=ts.mean(), color='r', linestyle='--', lw=2)
# Plot CI
ax.axhline(y=ts.mean() + 1.96*np.sqrt(np.var(ts)), color='g', linestyle=':', lw=2)
ax.axhline(y=ts.mean() - 1.96*np.sqrt(np.var(ts)), color='g', linestyle=':', lw=2)