如何使用带有分组变量的自定义描述函数来按组获取统计信息?
How to use customized describe function with a grouping variable to get statistics by group?
我试图通过分组变量获取特定变量的描述性统计信息。我希望输出中的百分位数比 describe 函数默认给出的更多。
我尝试了以下代码:
df.groupby('city')['population'].describe([0.01,0.05,0.25,0.50,0.75,0.90,0.95,0.99])
报错:
describe() takes 1 positional argument but 2 were given
你应该做什么 -- 正确调用函数
df.groupby('a')['b'].describe(percentiles=[0.01,0.05,0.25,0.50,0.75,0.90,0.95,0.99])
我试图通过分组变量获取特定变量的描述性统计信息。我希望输出中的百分位数比 describe 函数默认给出的更多。
我尝试了以下代码:
df.groupby('city')['population'].describe([0.01,0.05,0.25,0.50,0.75,0.90,0.95,0.99])
报错:
describe() takes 1 positional argument but 2 were given
你应该做什么 -- 正确调用函数
df.groupby('a')['b'].describe(percentiles=[0.01,0.05,0.25,0.50,0.75,0.90,0.95,0.99])