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¶
import pandas as pd
import numpy as np
Create a matrix¶
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()
Calculate average, variance, and standard deviation¶
Calculate by each function¶
df.mean()
df.var()
df.std()
Calculate using describe
¶
df.describe()