繁体   English   中英

添加一列,可以将数值分为低位数和高位数?

[英]add a column that can separate the numeric values into low median and high segments?

number = pd.DataFrame(np.random.randint(1,100,20).reshape(20,1), columns=['Number to segement'])

如何在其侧面添加一列,以根据列中的值自动将其分为几类(<25%,25%〜75%,> 75%)?

例:

在此处输入图片说明

pd.qcut几乎可以完全满足您的需求:

In [37]: number["quantile"] = pd.qcut(number["Number to segement"], [0, .25, .75, 1], labels=["<25%", "25-75%", ">75%"])

In [38]: number
Out[38]:
    Number to segement quantile
0                   53   25-75%
1                   85   25-75%
2                   95     >75%
3                   96     >75%
4                   60   25-75%
5                   37   25-75%
6                   32     <25%
7                   42   25-75%
8                   50   25-75%
9                   32     <25%
10                  30     <25%
11                  51   25-75%
12                  88     >75%
13                  76   25-75%
14                  10     <25%
15                  51   25-75%
16                  97     >75%
17                   1     <25%
18                  23     <25%
19                  87     >75%

如果省略了labels参数,则如果希望查看这些值,它将返回截止值。

<bound method ndframe._add_numeric_operations.... help! **replacing missing values with the median**< div><div id="text_translate"><p> 下图中显示的列有缺失值,我试图用中位数替换它们。 我不知道它是否有效,但它一直显示<strong><bound method NDFrame._add_numeric_operations</strong>我不知道这意味着什么,而且它不太好,因为它应该在缺失值的地方显示中值.</p><p> 图片链接:<a href="https://i.stack.imgur.com/YYctQ.png" rel="nofollow noreferrer">绑定方法</a><a href="https://i.stack.imgur.com/N6OeY.png" rel="nofollow noreferrer">绑定</a>方法1</p></div></bound>

[英]<bound method NDFrame._add_numeric_operations.... HELP! **Replacing Missing Values with the Median**

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM