Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pandas.cut不';垃圾箱零值_Python_Pandas - Fatal编程技术网

Python pandas.cut不';垃圾箱零值

Python pandas.cut不';垃圾箱零值,python,pandas,Python,Pandas,我正在尝试使用以下建议的列表将列分类为自定义类别- 我怎样才能做到: 0为[0,1] 和200作为(100,…)或>100类别?您应该添加np.inf bins =[-np.inf,1, 5, 10, 25, 50, 100, np.inf] df['Bins'] = pd.cut(df['Numbers'], bins,include_lowest =True) df Out[580]: Numbers Bins 0 0 (-inf, 1.0] 1

我正在尝试使用以下建议的列表将列分类为自定义类别-

我怎样才能做到:

0为[0,1]
和200作为(100,…)或>100类别?

您应该添加
np.inf

bins =[-np.inf,1, 5, 10, 25, 50, 100, np.inf]
df['Bins'] = pd.cut(df['Numbers'], bins,include_lowest =True)
df
Out[580]: 
   Numbers          Bins
0        0   (-inf, 1.0]
1        1   (-inf, 1.0]
2        2    (1.0, 5.0]
3        7   (5.0, 10.0]
4       11  (10.0, 25.0]
5       16  (10.0, 25.0]
6       45  (25.0, 50.0]
7      200  (100.0, inf]

嗯,这个问题似乎是个骗局。最好的办法是删除答案,你觉得怎么样?我实际上在想我是否应该撤销dup。include_lower处理0的情况,但不处理200的情况。@DSM最高的仍然不包括在内,这就是我使用np的原因。inf@cᴏʟᴅsᴘᴇᴇᴅ 200仍然不包括,即使我们添加了include_lowest=trueOK,也有意义+1.
bins =[-np.inf,1, 5, 10, 25, 50, 100, np.inf]
df['Bins'] = pd.cut(df['Numbers'], bins,include_lowest =True)
df
Out[580]: 
   Numbers          Bins
0        0   (-inf, 1.0]
1        1   (-inf, 1.0]
2        2    (1.0, 5.0]
3        7   (5.0, 10.0]
4       11  (10.0, 25.0]
5       16  (10.0, 25.0]
6       45  (25.0, 50.0]
7      200  (100.0, inf]