熊猫剪功能挂

时间:2018-11-29 16:13:06

标签: python pandas

我正在使用熊猫23.4。正在测试cut函数。我以前没用过我的测试:

x = [1.1e9, 1.4e9, 2.3e9, 3e9, 3.4e9, 4.4e9]
pd.cut(x, 1e9)

此挂起,python最终将其杀死。我希望它从0到5e9均匀地减少1e9。

1 个答案:

答案 0 :(得分:3)

IIUC

pd.cut(pd.Series(x), bins=range(0,int(6e9),int(1e9)))
Out[392]: 
0    (1000000000, 2000000000]
1    (1000000000, 2000000000]
2    (2000000000, 3000000000]
3    (2000000000, 3000000000]
4    (3000000000, 4000000000]
5    (4000000000, 5000000000]
dtype: category
Categories (5, interval[int64]): [(0, 1000000000] < (1000000000, 2000000000] <
                                  (2000000000, 3000000000] < (3000000000, 4000000000] <
                                  (4000000000, 5000000000]]