# 8 examples of 'python percentile' in Python

Every line of 'python percentile' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``84def percentile(n):85    def percentile_(x):86        return np.percentile(x, n)8788    percentile_.__name__ = 'percentile_%s' % n89    return percentile_``
``44def get_percentile(self, percentile):45    sum = 046    index = 047    while sum &lt; percentile * self.total:48        sum += self.buckets[index]49        index += 150    51    if index == 0:52        return 053    elif index - 1 &gt;= len(self.BUCKET_OFFSETS):54        return sys.maxint55    else:56        return self.BUCKET_OFFSETS[index - 1] - 1``
``53def percentile(self, histogram, bins, percent):54  """ Calculate the &lt;&gt; percentile of the histogram """55  # handle &gt; 100 or &lt; 056  if float(percent) &lt;= 0:57    return 058  elif float(percent) &gt;= 100:59    return bins[-1]6061  # if histogram is all 0s, return 062  if len(np.nonzero(histogram)[0]) == 0:63    return 06465  # normalize the histogram66  hist_norm = np.zeros(histogram.shape)67  68  hist_sum = 0.0 # dividing by a float ensures we get a float for normalized histograms69  for binval in histogram:70    hist_sum += binval71  72  for i, binval in enumerate(histogram):73    hist_norm[i] = histogram[i] / hist_sum7475  # compute the percentile using the normalized histogram76  bin_sum = 0.0 # the normalized histogram is floating point 77  i = 078  pfloat = float(percent) * 0.01 79  while bin_sum &lt; pfloat and i &lt; hist_norm.shape[0]:80    bin_sum += hist_norm[i]81    i += 18283  if i+1 &gt;= len(bins):84    return bins[-1]8586  return bins[i+1]``
``617def _func(self, values, axis=1, **kwargs):618    return pd.np.percentile(values, kwargs["value"], axis=axis)``
``366def percentile(values, p):367    if not isinstance(p, float) or not(0.0 &lt;= p &lt;= 1.0):368        raise ValueError("p must be a float in the range [0.0; 1.0]")369370    values = sorted(values)371    if not values:372        raise ValueError("no value")373374    k = (len(values) - 1) * p375    f = math.floor(k)376    c = math.ceil(k)377    if f != c:378        d0 = values[f] * (c - k)379        d1 = values[c] * (k - f)380        return d0 + d1381    else:382        return values[int(k)]``
``290def percentile25(arr):291    return np.percentile(arr, (25), interpolation='midpoint')``
``52def percentile(results, percent):53    return _percentile(sorted(results), percent)``
``16def get_percentile(stat):17    if not stat.startswith('percentile_'):18        raise ValueError("must start with 'percentile_'")19    qstr = stat.replace("percentile_", '')20    q = float(qstr)21    if q &gt; 100.0:22        raise ValueError('percentiles must be &lt;= 100')23    if q &lt; 0.0:24        raise ValueError('percentiles must be &gt;= 0')25    return q``