0

我想知道是否有一个代码可以计算我的数据集中有多少达到 25%、50%、75%,以及是否有办法手动调整四分位数,如 20% 40% 60% 80% 等.

Out[1]: 
              ALC (mins)
       count  303.000000
       mean   24.928812
       std    18.316443
       min    3.120000
       25%    12.680000
       50%    20.770000
       75%    30.535000
       max    143.180000
4

1 回答 1

1

使用percentiles可选参数:

>>> df.describe(percentiles = [0.2, 0.4, 0.6, 0.8])
           (mins)
count    8.000000
mean    69.566282
std    104.255870
min      3.120000
20%     14.934577
40%     20.279289
50%     22.849406
60%     26.050050
80%     98.122000
max    303.000000

计算每个四分位数有多少元素:

np.linspace(1, len(df), 5, dtype = np.int64)  # division by 5 since it starts from min, to 25%, 50%, 75%, then max.
于 2020-01-03T17:54:09.543 回答