熊猫 - 传播方差

时间:2016-08-09 23:22:34

标签: python pandas

表格数据

mean            var             count
31.5910645161   747.570011484   310
45.7            350.0658        2
77.2548205128   4968.46005809   195
166.830361446   13755.5734253   166
40.29           208.8968        2
254.35          15204.1922      2
4.81            0.0             1
56.0124200913   962.697805171   1533
114.25          0.0             1
24.12           422.257129412   18

以后会有更多的重复计数。我需要groupby('count').agg('mean','var')才能正确传播方差。但是,该代码不起作用(mean和var不知道如何处理2列),当然只使用mean是不可能的(方差的均值不是均值的方差)。你如何做到这一点,以便方差得到正确的发送?

1 个答案:

答案 0 :(得分:0)

Parameters
----------
arg : function or dict
    Function to use for aggregating groups. If a function, must either
    work when passed a DataFrame or when passed to DataFrame.apply. If
    passed a dict, the keys must be DataFrame column names.

    Accepted Combinations are:
      - string cythonized function name
      - function
      - list of functions
      - dict of columns -> functions
      - nested dict of names -> dicts of functions

当您需要传递字符串列表时,您传递了两个字符串。

df.groupby('count').agg(['mean','var'])

enter image description here