python - Pandas 获得高于组中位数的组数

标签 python pandas

给定一个带有分类列 family 和数字列 score 的 Pandas 数据框,我想计算 family 的那些人的数量(或低于)该家庭的中位数分数

概念上类似的东西? df.groupby('family')['score'].median().filter(lambda x: x>x.median)

有什么帮助吗?

最佳答案

听起来你在找类似的东西

df[df.score > df.groupby('family').score.transform('median')].groupby('family').count()

关于python - Pandas 获得高于组中位数的组数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46798731/

相关文章:

python - key 错误 : "None of [Float64Index([34.62365962451697, 30.28671076822607, 35.84740876993872], dtype=' float6 4')] are in the [columns]"

python - 如何将 Pandas DataFrame 与列表字典合并

python - 删除行读取引起的回车

python - 管理服务器上脚本的运行

python - Pandas : compute mean or std (standard deviation) over entire dataframe

python - 在Python中将年份添加到日期(d-m-y)列

python - 如何在 Pandas 中一次计算均值和标准差?

对列表中的项目进行分组的 Pythonic 方法

python - 如何在 CentOS 上降级 python 版本?

python - SOAP、Python、 SOAP 水