Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.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中的空容器_Python_Pandas_Bin_Binning - Fatal编程技术网

减少python中的空容器

减少python中的空容器,python,pandas,bin,binning,Python,Pandas,Bin,Binning,我对python中的binning很陌生,我正在尝试创建带有房价的bins。我希望我的最后一个垃圾箱是4000000+以减少空垃圾箱 这是我的密码: bins = np.arange(0, 13000000, 1000000) print(bins) labels = pd.cut(data['PRICE'], bins, right= True) labels = labels.value_counts().sort_index() labels 输出是 (0, 1000000]

我对python中的binning很陌生,我正在尝试创建带有房价的bins。我希望我的最后一个垃圾箱是4000000+以减少空垃圾箱

这是我的密码:

bins = np.arange(0, 13000000, 1000000)
print(bins)
labels = pd.cut(data['PRICE'], bins, right= True)
labels = labels.value_counts().sort_index()
labels
输出是

(0, 1000000]            869
(1000000, 2000000]       88
(2000000, 3000000]       20
(3000000, 4000000]        4
(4000000, 5000000]        1
(5000000, 6000000]        1
(6000000, 7000000]        0
(7000000, 8000000]        0
(8000000, 9000000]        0
(9000000, 10000000]       0
(10000000, 11000000]      0
(11000000, 12000000]      1

如何将垃圾箱减少到4000000或以上,使其频率达到3

这应该在这里起作用,您必须手动设置垃圾箱边界:

bins = [1000000,2000000,3000000,4000000,12000000]
print(bins)
labels = pd.cut(data['PRICE'], bins, right= True)
labels = labels.value_counts().sort_index()
labels
此外,请在此查看关于该主题的不同答案:


可能重复感谢您的帮助!没问题。如果这对你有帮助,你介意回答吗?干杯:)