Descriptive Statistics
Simple Statistics¶
There are quite a few simple statistics we can begin with. The maximum, the minimum, and using describe to get a high level overview of the data.
In [2]:
#Let's find the max
print(df.max())
In [3]:
#And the min
print(df.min())
In [4]:
#Describe the data
print(df.describe())
Let's also graph this stock price.
In [5]:
import matplotlib.pyplot as plt
df.plot(kind="line",color="k")
plt.xlabel("T")
plt.ylabel("Stock Price")
plt.title("Historical Stock Price")
plt.show()
Going back to the prior lecture, we learned about rolling windows. Let's once again use this.
In [6]:
#Let's get a rolling mean dataframe
rolling_mean = df.rolling(window=22).mean()
print(rolling_mean)
Now overlay the rolling mean on the true prices.
In [7]:
#Plot our rolling mean over our real data
df.plot(kind="line",color="k")
rolling_mean.plot(kind="line",color="b")
plt.show()
We can also get a rolling standard deviation of the stock price.
In [8]:
#We can also get the standard deviation for each rolling window
std = df.rolling(window=22).std()
print(std)
In [9]:
std.plot(kind="line")
plt.xlabel("t")
plt.ylabel("sigma")
plt.title("Rolling Standard Deviation")
plt.show()