Weighted percentile using numpy

前端 未结 12 2221
一个人的身影
一个人的身影 2020-12-01 03:28

Is there a way to use the numpy.percentile function to compute weighted percentile? Or is anyone aware of an alternative python function to compute weighted percentile?

12条回答
  •  孤城傲影
    2020-12-01 04:12

    The weightedcalcs package supports quantiles:

    import weightedcalcs as wc
    import pandas as pd
    
    df = pd.DataFrame({'v': [1, 2, 3], 'w': [3, 2, 1]})
    calc = wc.Calculator('w')  # w designates weight
    
    calc.quantile(df, 'v', 0.5)
    # 1.5
    

提交回复
热议问题