def weighted_percentile(data, percents, weights=None):
    """ percents in units of 1%
    weights specifies the frequency (count) of data.
    """
if weights is None:
    return np.percentile(data, percents)
ind = np.argsort(data)
d = data[ind]
w = weights[ind]
p = 1.0 * w.cumsum() / w.sum() * 100
y = np.interp(percents, p, d)
return y
Weighted percentile using numpy