Python计算每个分位数和预设四分位数。

huangapple go评论106阅读模式
英文:

Python Count per quantiles and pre set quartiles

问题

我想知道是否有一种代码,可以计算我的数据集中有多少比例的数据落在25%,50%,75%这些位置,并且是否可以手动调整四分位数,例如20%,40%,60%,80%等。

  1. Out[1]:
  2. ALC (mins)
  3. count 303.000000
  4. mean 24.928812
  5. std 18.316443
  6. min 3.120000
  7. 25% 12.680000
  8. 50% 20.770000
  9. 75% 30.535000
  10. max 143.180000
  11. ```
  12. <details>
  13. <summary>英文:</summary>
  14. I want to know if there is a code wherein I can count how many in my dataset goes to 25%, 50%, 75% and if there is a way to adjust the quartiles manually like 20% 40% 60% 80%, etc.
  15. ````python
  16. Out[1]:
  17. ALC (mins)
  18. count 303.000000
  19. mean 24.928812
  20. std 18.316443
  21. min 3.120000
  22. 25% 12.680000
  23. 50% 20.770000
  24. 75% 30.535000
  25. max 143.180000
  26. </details>
  27. # 答案1
  28. **得分**: 2
  29. 使用`percentiles`可选参数
  30. ```python
  31. &gt;&gt;&gt; df.describe(percentiles = [0.2, 0.4, 0.6, 0.8])
  32. (mins)
  33. count 8.000000
  34. mean 69.566282
  35. std 104.255870
  36. min 3.120000
  37. 20% 14.934577
  38. 40% 20.279289
  39. 50% 22.849406
  40. 60% 26.050050
  41. 80% 98.122000
  42. max 303.000000
  43. ```
  44. 用于计算每个四分位数中的元素数量
  45. ```python
  46. np.linspace(1, len(df), 5, dtype = np.int64) # 除以5,因为它从最小值开始,然后是25%,50%,75%,最后是最大值。
  47. ```
  48. <details>
  49. <summary>英文:</summary>
  50. Use `percentiles` optional argument:
  51. &gt;&gt;&gt; df.describe(percentiles = [0.2, 0.4, 0.6, 0.8])
  52. (mins)
  53. count 8.000000
  54. mean 69.566282
  55. std 104.255870
  56. min 3.120000
  57. 20% 14.934577
  58. 40% 20.279289
  59. 50% 22.849406
  60. 60% 26.050050
  61. 80% 98.122000
  62. max 303.000000
  63. For counting how much elements will per quartile:
  64. np.linspace(1, len(df), 5, dtype = np.int64) # division by 5 since it starts from min, to 25%, 50%, 75%, then max.
  65. </details>

huangapple
  • 本文由 发表于 2020年1月4日 01:42:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/59583021.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定