从连续变量 Python 创建多个 类

Create multiple classes from continuous variables Python

我想将我的连续预测变量(股票 returns)转换为分类变量(5 个箱子,5 个箱子具有相同数量的股票或绝对阈值,比如 -30% 到 -20% , 然后是 -19% 到 -10% 等等)

是否有一些 Python 包可以做到这一点? scikit 学习等?

您正在寻找的似乎是 pandas.cut for absolute thresholds or pandas.qcut 相同大小的垃圾箱。

numpy.histogram 也是离散化东西的有用选项