Last active
May 19, 2021 15:13
-
-
Save zencd/39e044cdd42b01ec2f03fb5d8386327e to your computer and use it in GitHub Desktop.
pure python percentile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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