Computes a percentile of a given Pmf.

    percentage: float 0-100
506711
def Percentile(pmf, percentage):
    
    p = percentage / 100.0
    total = 0
    for val, prob in pmf.Items():
        total += prob
        if total >= p:
            return val
309060
def percentileofscore(inlist, score, histbins=10, defaultlimits=None):
    

    h, lrl, binsize, extras = histogram(inlist, histbins, defaultlimits)
    cumhist = cumsum(copy.deepcopy(h))
    i = int((score - lrl) / float(binsize))
    pct = (cumhist[i - 1] + ((score - (lrl + binsize * i)) / float(binsize)) * h[i]) / float(len(inlist)) * 100
    return pct
528378
def quantiles(self, k=5):
        """"""
        arr = self.array()
        q = list(np.linspace(0, 100, k))
        return np.percentile(arr.compressed(), q)
588002
def valueAt( self, percent ):
        
        minim = self.minimum()
        maxim = self.maximum()
        rtype = self.rulerType()
        
        # simple minimum
        if ( percent <= 0 ):
            return minim
        
        # simple maximum
        elif ( 1 <= percent ):
            return maxim
        
        # calculate a numeric percentage value
        elif ( rtype == XChartRuler.Type.Number ):
            return (maxim - minim) * percent
        
        # calculate a time percentage value
        elif ( rtype in (XChartRuler.Type.Datetime, XChartRuler.Type.Time) ):
            maxsecs = minim.secsTo(maxim)
            
            diff = maxssecs * percent
            return minim.addSecs(diff)
            
        # calculate a date percentage value
        elif ( rtype == XChartRuler.Type.Date ):
            maxdays = minim.daysTo(maxim)
            
            diff = maxdays * percent
            return minim.addDays(diff)
            
        # otherwise, compare against the notches
        else:
            perc    = 0.0
            notches = self.notches()
            count   = len(notches)
            count  += self.padStart() + self.padEnd()
            count   = max(1, count - 1)
            
            perc    = float(self.padStart()) / count
            last    = None
            
            for i, notch in enumerate(notches):
                perc += float(i) / count
                if ( perc <= percent ):
                    break
                
                last = notch
            
            return last
1089227
public function calculatePercentage($decimal = 1)
    {
        // Profile not loaded yet.
        if (is_null($this->percentile)) {
            return null;
        }

        // Calculate percentage and return value
        return (float) number_format($this->percentile * 100, $decimal, '.', '');
    }
491219
public int getValueAtPercentile(double percentile) {
        int permyriad = (int) (percentile * 100);
        switch (permyriad) {
            case 0: return p0;
            case 500: return p5;
            case 1000: return p10;
            case 1500: return p15;
            case 2000: return p20;
            case 2500: return p25;
            case 3000: return p30;
            case 3500: return p35;
            case 4000: return p40;
            case 4500: return p45;
            case 5000: return p50;
            case 5500: return p55;
            case 6000: return p60;
            case 6500: return p65;
            case 7000: return p70;
            case 7500: return p75;
            case 8000: return p80;
            case 8500: return p85;
            case 9000: return p90;
            case 9500: return p95;
            case 9900: return p99;
            case 9950: return p99_5;
            case 9990: return p99_9;
            case 9995: return p99_95;
            case 9999: return p99_99;
            case 10000: return p100;
            default: throw new IllegalArgumentException("Percentile (" + percentile + ") is not currently cached");
        }
    }
1022304
def rolling_percentileofscore(series, window, min_periods=None):
    """"""
    import scipy.stats as stats

    def _percentile(arr):
        score = arr[-1]
        vals = arr[:-1]
        return stats.percentileofscore(vals, score)

    notnull = series.dropna()
    min_periods = min_periods or window
    if notnull.empty:
        return pd.Series(np.nan, index=series.index)
    else:
        return pd.rolling_apply(notnull, window, _percentile, min_periods=min_periods).reindex(series.index)
858496
def percentile(self, p):
        

        if not (0 <= p <= 100):
            raise ValueError("p must be between 0 and 100, inclusive.")

        p = float(p)/100.
        p *= self.n
        c_i = None
        t = 0

        if p == 0:
            return self.C.min_item()[1].mean

        for i, key in enumerate(self.C.keys()):
            c_i_plus_one = self.C[key]
            if i == 0:
                k = c_i_plus_one.count / 2

            else:
                k = (c_i_plus_one.count + c_i.count) / 2.
                if p < t + k:
                    z1 = p - t
                    z2 = t + k - p
                    return (c_i.mean * z2 + c_i_plus_one.mean * z1) / (z1 + z2)
            c_i = c_i_plus_one
            t += k

        return self.C.max_item()[1].mean
298052
def percent_rank(expr, sort=None, ascending=True):
    
    return _rank_op(expr, PercentRank, types.float64, sort=sort, ascending=ascending)
213161
def median(self, name, **kwargs):
        
        data = self.get(name,**kwargs)
        return np.percentile(data,[50])
1217208
def as_percent(self, precision=2, *args, **kwargs):
        
        f = Formatter(as_percent(precision), args, kwargs)
        return self._add_formatter(f)
193453
def perc(arr, p=95, **kwargs):
    """"""
    offset = (100 - p) / 2
    return np.percentile(arr, (offset, 100 - offset), **kwargs)
676721
def get_percentage_from_prob(prob):
    
    assert isinstance(prob, (float, int))
    prob = float(prob)
    assert prob >= 0
    assert prob <= 1

    percentages = list(probability_list.keys())
    percentages.sort()
    for percentage in percentages:
        if prob < probability_list[percentage]:
            return percentage - 1
    return 100
15423
function percentile(arr, p) {
    if (arr.length === 0) return 0;
    if (typeof p !== 'number') throw new TypeError('p must be a number');
    if (p <= 0) return arr[0];
    if (p >= 1) return arr[arr.length - 1];

    var index = arr.length * p,
        lower = Math.floor(index),
        upper = lower + 1,
        weight = index % 1;

    if (upper >= arr.length) return arr[lower];
    return arr[lower] * (1 - weight) + arr[upper] * weight;
}
654626
def fast_median(a):
    
    a = checkma(a)
    #return scoreatpercentile(a.compressed(), 50)
    if a.count() > 0:
        out = np.percentile(a.compressed(), 50)
    else:
        out = np.ma.masked
    return out
1343638
def results_with_percent(self):
        

        percents = [int(float(v) / sum(self.votes) * 100) if sum(self.votes) > 0 else 0 for v in self.votes]
        return zip(self.options, self.votes, percents)
363303
def percentile(perc)
      if perc > 100.0 || perc < 0.0
        raise InvalidPercentile, "percentile must be between 0.0 and 100.0"
      end
      return 0.0 if data.empty?

      rank = (perc / 100.0) * (size + 1)

      return data[0]          if rank < 1
      return data[-1]         if rank > size
      return data[rank - 1]   if rank == Integer(rank)
      weighted_average_for(rank)
    end