Calculate The Average, Variance, And Standard Deviation
Goal¶
This post aims to introduce how to calculate the average, variance and standard deviation of matrix using pandas
.
Libraries¶
In [2]:
import pandas as pd
import numpy as np
Create a matrix¶
In [13]:
n = 1000
df = pd.DataFrame({'rand': np.random.rand(n),
'randint': np.random.randint(low=0, high=100, size=n),
'randn': np.random.randn(n),
'random_sample': np.random.random_sample(size=n),
'binomial': np.random.binomial(n=1, p=.5, size=n),
'beta': np.random.beta(a=1, b=1, size=n),
})
df.head()
Out[13]:
Calculate average, variance, and standard deviation¶
Calculate by each function¶
In [16]:
df.mean()
Out[16]:
In [15]:
df.var()
Out[15]:
In [17]:
df.std()
Out[17]:
Calculate using describe
¶
In [18]:
df.describe()
Out[18]:
Comments
Comments powered by Disqus