我想得到我numpy.std
的每一栏pandas.DataFrame
.
这是我的代码:
import pandas as pd import numpy as np prices = pd.DataFrame([[-0.33333333, -0.25343423, -0.1666666667], [+0.23432323, +0.14285714, -0.0769230769], [+0.42857143, +0.07692308, +0.1818181818]]) print(pd.DataFrame(prices.std(axis=0)))
这是我的代码输出:
pd.DataFrame([[ 0.39590933], [ 0.21234018], [ 0.1809432 ]])
这是正确的输出(如果计算np.std
)
pd.DataFrame([[ 0.32325862], [ 0.17337503], [ 0.1477395 ]])
为什么我有这样的差异?我该如何解决这个问题?
注意:我试过这样做:
print(np.std(prices, axis=0))
但我有以下错误:
Traceback (most recent call last): File "C:\Users\*****\Documents\******\******\****.py", line 10, inprint(np.std(prices, axis=0)) File "C:\Python33\lib\site-packages\numpy\core\fromnumeric.py", line 2812, in std return std(axis=axis, dtype=dtype, out=out, ddof=ddof) TypeError: std() got an unexpected keyword argument 'dtype'
谢谢!