我有一个如下所示的数据框
df = pd.DataFrame({
'subject_id':[1,1,1,1,2,2,2,2,3,3,4,4,4,4,4],
'readings' : ['READ_1','READ_2','READ_1','READ_3','READ_1','READ_5','READ_6','READ_8','READ_10','READ_12','READ_11','READ_14','READ_09','READ_08','READ_07'],
'val' :[5,6,7,11,5,7,16,12,13,56,32,13,45,43,46],
})
我想做的是获取现有列的描述性统计/汇总形式,而不是拥有原始列。我希望看到 ( min, max, 25%, 75%, std, var) 作为每个主题的新列
我尝试了以下但输出不准确
df.groupby(['subject_id','readings']).describe().reset_index() #this gives some output but it isn't exact
df.groupby(['subject_id','readings']).pivot_table(values='val', index='subject_id', columns='readings').describe() # this throws error
我希望我的输出如下所示。基本上它将是一个宽而稀疏的矩阵。由于屏幕截图很宽,我无法进一步放大。如果单击图像,您将更好地显示预期输出
jeck猫
相关分类