简体   繁体   English

Pandas Cut 中的分箱

[英]Binning in Pandas Cut

I am using Pandas cut to bin certain values in ranges according to a column.我正在使用 Pandas cut 根据列对范围内的某些值进行分组。 I am using user defined bins ie the ranges are being passed as array.我正在使用用户定义的垃圾箱,即范围作为数组传递。

df['Range'] = pd.cut(df.TOTAL, bins=[0,100,200,300,400,450,500,600,700,800,900,1000,2000])

However the values I have are ranging till 100000. This restricts the values to 2000 as an upper limit, and I am losing values greater than 2000. I want to keep an interal for greater than 2000. Is there any way to do this?但是,我拥有的值范围是 100000。这将值限制为 2000 作为上限,并且我丢失了大于 2000 的值。我想保留大于 2000 的内部值。有什么办法可以做到这一点?

让我们将np.inf添加到 bin 列表的末尾:

pd.cut(df.TOTAL, bins=[0,100,200,300,400,450,500,600,700,800,900,1000,2000,np.inf])

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

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