[英]Pandas.cut specify custom range
Is it possible to specify a custom range in pandas.cut
?是否可以在
pandas.cut
指定自定义范围?
I have a dataset where I need to bin the age column (and several other columns).我有一个数据集,我需要将年龄列(和其他几个列)合并到其中。 The
min
and the max
value of age
in the dataset is 18
and 55
, respectively.数据集中
age
的min
和max
分别为18
和55
。 However, in the documentation of the dataset, it is written that the range of the attribute age
is 18-58
.但是,在数据集的文档中,写了属性
age
的范围是18-58
。
pandas.cut
will automatically bin according to the range of the dataset (which will be 18-55
), which is wrong. pandas.cut
会根据数据集的范围(将是18-55
)自动pandas.cut
,这是错误的。
Is there any way I can specify the range to bin on in the pandas.cut
method?有什么办法可以在
pandas.cut
方法中指定要pandas.cut
的范围吗? I looked into IntervalIndex
tuples as bins, but that would mean that I generate the bins manually myself.我将
IntervalIndex
元组视为垃圾箱,但这意味着我自己手动生成垃圾箱。 I am looking for if pandas.cut
has this functionality built-in.我正在寻找
pandas.cut
是否内置了此功能。
No, not directly.不,不是直接的。
However, you could pass np.linspace(18, 58, n_bins)
to pd.cut
.但是,您可以将
np.linspace(18, 58, n_bins)
传递给pd.cut
。 I'm not sure if you consider that "generating manually".我不确定您是否考虑“手动生成”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.