Skip to content

Instantly share code, notes, and snippets.

@maptastik
Created October 7, 2019 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maptastik/961bb5a7984414080f55116b688e3095 to your computer and use it in GitHub Desktop.
Save maptastik/961bb5a7984414080f55116b688e3095 to your computer and use it in GitHub Desktop.
def quantile_bins(quantiles, min = 0, max = 100):
"""Return a list of quantiles including floor and ceiling values
Args:
quantile (list): Quantile values in order
min (numeric): Floor value of data range
max (numeric): Ceiling value of data range
Returns:
list: An inclusive list of quantile bin values
Examples:
>>> quantile_bins([13.18221923304911, 15.913682562603704, 23.990235841052815, 44.71041388741459])
[0, 13.18221923304911, 15.913682562603704, 23.990235841052815, 44.71041388741459, 100]
"""
#######################
## INPUT VALUE TESTS ##
#######################
if not isinstance(min, (int, float)):
raise TypeError("Value should be an integer or float.")
if not isinstance(max, (int, float)):
raise TypeError("Value should be an integer or float.")
if not isinstance(quantiles, list):
raise TypeError("The quantiles should be passed as a list.")
######################
## FUNCTION PROCESS ##
######################
return [min] + quantiles + [max]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment