-
Pandas Basics 5
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
Lecture1.5
-
-
Data Transformations 6
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
Lecture2.5
-
Lecture2.6
-
-
Statistics 4
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
-
Reading and Writing Data 3
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
-
Joins 5
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Lecture5.4
-
Lecture5.5
-
-
Grouping 4
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
Lecture6.4
-
-
Introduction to Numpy 4
-
Lecture7.1
-
Lecture7.2
-
Lecture7.3
-
Lecture7.4
-
-
Randomness 2
-
Lecture8.1
-
Lecture8.2
-
-
Numpy Data Functionality 1
-
Lecture9.1
-
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())
121.3377629695897
In [3]:
#And the min
print(df.min())
93.6404950441195
In [4]:
#Describe the data
print(df.describe())
count 200.000000
mean 103.011855
std 5.725281
min 93.640495
25% 98.107869
50% 103.830988
75% 106.844638
max 121.337763
dtype: float64
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)
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
...
195 108.392252
196 108.959444
197 109.601481
198 110.265314
199 111.035135
Length: 200, dtype: float64
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)
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
...
195 4.604318
196 4.934126
197 5.217633
198 5.548086
199 5.861845
Length: 200, dtype: float64
In [9]:
std.plot(kind="line")
plt.xlabel("t")
plt.ylabel("sigma")
plt.title("Rolling Standard Deviation")
plt.show()
Prev
Introduction
Next
Bollinger Bands