Skip to main content

np.percentile()

np.percentile(arr, p)

Returns the p-th percentile of the numbers in arr.

Input:
arr : array
The array to calculate the percentile of.
p : float or array of floats
Percentile or sequence of percentiles to compute, all of which must be between 0 and 100 inclusive.
Returns:
The p-th percentile of the array values.
Return Type:
float or ndarray
The result is a single float if p is a single percentile or an ndarray if multiple percentiles are given.

weight_ser = pets.get('Weight')
weight_ser
  • dog_00140
  • cat_00115
  • cat_00220
  • dog_00280
  • dog_00325
  • ham_0011
  • ham_0020.25
weight_arr = np.array(weight_ser)
weight_arr

array([40. , 15. , 20. , 80. , 25. , 1. , 0.25])

np.percentile(weight_arr, 50)

12.5