Skip to content

Instantly share code, notes, and snippets.

@eLtronicsVilla
Created May 24, 2019 13:57
Show Gist options
  • Save eLtronicsVilla/2c9b9c90e140e7e1d7c3f6d1092dfb89 to your computer and use it in GitHub Desktop.
Save eLtronicsVilla/2c9b9c90e140e7e1d7c3f6d1092dfb89 to your computer and use it in GitHub Desktop.
# Generalization of median is quantile. Which represent the value less than which a certain percentile of the data lies.
num = [100, 49, 41, 40, 25]
def quantile(x, p):
"""returns the pth-percentile value in x data list"""
p_index = int(p * len(x))
return sorted(x)[p_index]
print("quantile",quantile(num, 0.10))
def interquartile_range(data):
return quantile(data,0.75) - quantile(data,0.25)
print("interquartile_range:",interquartile_range(num))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment