Skip to content

Instantly share code, notes, and snippets.

@zencd
Last active May 19, 2021 15:13
Show Gist options
  • Save zencd/39e044cdd42b01ec2f03fb5d8386327e to your computer and use it in GitHub Desktop.
Save zencd/39e044cdd42b01ec2f03fb5d8386327e to your computer and use it in GitHub Desktop.
pure python percentile
import math
def percentile(data, perc: int):
return sorted(data)[int(math.ceil(len(data) * perc / 100)) - 1]
assert 9.0 == percentile([10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0], 90)
assert 146 == percentile([142, 232, 290, 120, 274, 123, 146, 113, 272, 119, 124, 277, 207], 50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment