如何使用Pandas中的透视表计算标准差?

2024-06-07 12:06:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一堆数据,涉及特定运动的某些运动员的特定数字。我想用Pandas中的pivot表将数据按体育项目进行划分,并为每项运动对应的值提供所有参加该项运动的人的平均“数字”值。(因此,如果是篮球,它将平均所有打篮球的球员的数量,这个数字基本上代表了一种偏好。)

我可以用pivot表很容易地做到这一点,但是如果我想用同样的方法来计算标准差,我就不知道怎么做了。我可以做np.mean来计算平均值,但是没有{}。我知道有std(),但我不确定在这种情况下如何使用它。在

透视表不适合执行此任务吗?我该如何找出某项运动中所有运动员的数字数据的标准差?在


Tags: 数据方法pandas数量np代表数字mean
2条回答

你在用什么版本的numpy?1.9.2有np.标准公司名称:

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.

如果您有一个数据帧(df)和一个名为"sport"的列,那么它很简单:

df.groupby(by=['sport']).std()

相关问题 更多 >

    热门问题