Calculate numpy.std of each pandas.DataFrame's column?

前端 未结 1 889
天命终不由人
天命终不由人 2020-12-21 09:30

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
         


        
相关标签:
1条回答
  • 2020-12-21 09:57

    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 ])
    
    0 讨论(0)
提交回复
热议问题