我有一堆数据,涉及特定运动的某些运动员的某些数字。我想使用Pandas中的数据透视表将数据按运动拆分,每项运动的对应值都有该运动所有人的平均“数字”值。(因此,如果是篮球,它将平均所有打篮球的球员的数量,这个数字基本上代表了一种偏好。)
我可以用数据透视表很容易地做到这一点,但是如果我想做同样的事情来计算标准差,我不知道怎么做。我可以做np.mean
,但是没有np.std
。我知道有std()
,但我不确定在这种情况下该如何使用它。
做这个任务不建议使用数据透视表吗?我应该如何找到特定运动的所有运动员的数字数据的标准差?
发布于 2015-06-09 12:11:44
如果您有一个包含名为"sport"
的列的DataFrame (df
),那么它非常简单:
df.groupby(by=['sport']).std()
发布于 2015-06-09 12:02:59
您使用的是什么版本的numpy ? 1.9.2有np.std:
np.std?
Type: function
String form: <function std at 0x0000000003EE47B8>
File: c:\anaconda3\lib\site-packages\numpy\core\fromnumeric.py
Definition: np.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False)
Docstring:
Compute the standard deviation along the specified axis.
Returns the standard deviation, a measure of the spread of a distribution,
of the array elements. The standard deviation is computed for the
flattened array by default, otherwise over the specified axis.
发布于 2021-07-21 23:29:02
df.pivot_table(values='number', index='sport', aggfunc='std')
https://stackoverflow.com/questions/30722711
复制相似问题