熊猫:多级群组的聚合

时间:2013-06-06 02:06:23

标签: pandas

我的df看起来像这样:

      batch    group  reading  temp  test    block  delay
   0   9551  Control      340  22.9     1    X     35
   1   9551  Control      345  22.9     1    Y    35

我需要按“组”和“阻止”进行分组,例如我的意思是这样的:

df.groupby(['block', 'group']).reading.mean().unstack().transpose()

block       X           Y
group                          
Control  347.339450  350.427273
Trial    347.790909  350.668182

在这样切片的数据上调用像参数scipy.stats.ttest_ind这样的2参数函数的最佳方法是什么?所以我最终得到了一个t测试表

x中的对照与试验

控制vs试验y

x vs y in control

x vs y in trial

1 个答案:

答案 0 :(得分:0)

您是否想在应用t检验之前对数据进行分组和汇总?我想你想要选择数据的子集。分组可以做到这一点,但掩盖可能会更简单地完成工作。

副手,我会说你想要像

这样的东西
scipy.stats.ttest_ind(df[(df.group == 'Control') & (df.block == 'X')].reading, 
                      df[(df.group == 'Trial') & (df.block == 'X')].reading)
相关问题