需要帮助合并两个类别/时间间隔

时间:2019-08-16 06:10:21

标签: python-3.x numpy

我正在尝试合并并重命名通过qcut生成的以下间隔。这是该列上value_counts的结果。

(1533800.0, 2200000.0]     706
(659934.4, 1030736.0]      702
(12515.9, 659934.4]        701
(1030736.0, 1533800.0]     700
(2200000.0, 22745000.0]    696
Name: SANCT_LIMIT, dtype: int64

我正在像字符串一样比较间隔,我不确定这是否是正确的方法,或者是否还有其他方法。当我执行代码时,所有这些代码都被分配了不正确的类别5。

Num_BINS['SANCT_LIMIT'] = np.where((Num_BINS['SANCT_LIMIT'] == '(12515.9, 659934.4]') | (Num_BINS['SANCT_LIMIT'] == '(659934.4, 1030736.0]'),'Category 1',np.where(Num_BINS['SANCT_LIMIT'] == '(1030736.0, 1533800.0]',"Category 2",np.where(Num_BINS['SANCT_LIMIT'] == '(1533800.0, 2200000.0]',"Category 3",np.where(Num_BINS['SANCT_LIMIT'] == '(2200000.0, 22745000.0]',"Category 4","Category 5"))))

The result I want is 
Category 1 1403
Category 2 700
Category 3 706
Category 4 696

0 个答案:

没有答案