Skip to content

Instantly share code, notes, and snippets.

@maptastik
Created October 7, 2019 16:02
Show Gist options
  • Save maptastik/052413a998034c6b97c6148d88b2d488 to your computer and use it in GitHub Desktop.
Save maptastik/052413a998034c6b97c6148d88b2d488 to your computer and use it in GitHub Desktop.
def quantile_percentiles(quantile_count: int = 5) -> list:
"""Return quantile percentile values for a given number of quantiles.
Args:
quantile_count (int): Number of quantiles to generate percentile values for (default 5)
Returns:
list: Equally spaced quantile percentile values based on quantile_count
Examples:
>>> print(quantile_percentiles(10))
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
"""
#######################
## INPUT VALUE TESTS ##
#######################
if not isinstance(quantile_count, int):
raise TypeError("quantile_count must be an integer greater than 0")
if quantile_count < 1:
raise ValueError("quantile_count must be an integer greater than 0")
######################
## FUNCTION PROCESS ##
######################
quantile_percentiles = []
percentile_interval = (100 / quantile_count)
percentile_value = percentile_interval
while percentile_value < 100:
quantile_percentiles.append(percentile_value / 100)
percentile_value+=percentile_interval
return quantile_percentiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment