いくつかのコードがありますが、なぜnp.stdを適用すると2つの異なる結果が得られるのか理解できません。異なる結果np.std()がpandasとstandaloneで使用されている場合
import numpy as np
import pandas as pd
a = np.array([ 1.5, 6. , 7. , 4.5])
print 'mean value is:', a.mean()
print 'standard deviation is:', np.std(a)
次の行は、基本的には私が読むことができるnp.stdのドキュメントからパンダのデータフレーム
base = datetime.datetime(2000, 1, 1)
arr = np.array([base + datetime.timedelta(days=i) for i in xrange(4)])
index_date = pd.Index(arr, name = 'dates')
data_gas = pd.DataFrame(a, index_date, columns=['value'], dtype=float)
mean_pandas = data_gas.resample('M').mean()
standard_deviation = data_gas.resample('M').apply(np.std)
print mean_pandas
print standard_deviation
で同じことを行う必要があります:「...デフォルトでddof
はゼロです。」 (ddof =デルタ自由度)。
np.std(a)
は、除数がN(=値の数)である標準偏差を返します。...resample('M').apply(np.std)
は、除数がN-1の標準偏差を返します。
いずれの場合でも値を共有できますか? –
np.std(a)の結果は2.0767で、standard_deviationは2.3979を返します – paulchen
私が正しく理解していれば、あなたの質問は「なぜ、 '.apply(np.std)'が 'np.std'自体にもかかわらずddof = 1を使って計算するのですddof = 0?」となる。それは正しい解釈ですか? –