https://support.microsoft.com/en-us/office/covariance-p-function-6f0e1e6d-956d-4e4b-9943-cfef0bf9edfc
The formula =COVARIANCE.S(A1:A5,B1:B5) gives 6.5
3 | 9 | |
2 | 7 | |
4 | 12 | |
5 | 15 | |
6 | 17 | 6.5 |
Python 3 Jupyter Notebook
import pandas as pd, numpy as np
df = pd.DataFrame(list(zip([3,2,4,5,6], [9,7,12,15,17])), columns =['a', 'b'])
a | b | |
---|---|---|
0 | 3 | 9 |
1 | 2 | 7 |
2 | 4 | 12 |
3 | 5 | 15 |
4 | 6 | 17 |
df.cov()
a | b | |
---|---|---|
a | 2.5 | 6.5 |
b | 6.5 | 17.0 |
df.cov().iloc[0, 1]
6.5
沒有留言:
張貼留言