I want to get the numpy.std
of each column of my pandas.DataFrame
.
Here is my code:
import pandas as pd
import numpy as np
They're both right: they just differ on what the default delta degrees of freedom is. np.std uses 0, and DataFrame.std uses 1:
>>> prices.std(axis=0, ddof=0)
0 0.323259
1 0.173375
2 0.147740
dtype: float64
>>> prices.std(axis=0, ddof=1)
0 0.395909
1 0.212340
2 0.180943
dtype: float64
>>> np.std(prices.values, axis=0, ddof=0)
array([ 0.32325862, 0.17337503, 0.1477395 ])
>>> np.std(prices.values, axis=0, ddof=1)
array([ 0.39590933, 0.21234018, 0.1809432 ])