Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.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/8/python-3.x/19.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 我们可以使用pd.cut获得箱子和标签的中点或最右边的数字吗?_Python_Python 3.x_Pandas - Fatal编程技术网

Python 我们可以使用pd.cut获得箱子和标签的中点或最右边的数字吗?

Python 我们可以使用pd.cut获得箱子和标签的中点或最右边的数字吗?,python,python-3.x,pandas,Python,Python 3.x,Pandas,我正在测试这个代码 labels = pd.interval_range(start=0, freq=1, end=55) bins = pd.interval_range(start=0, freq=1, end=55) dataset['DVScores'] = pd.cut(dataset['DV'], bins=bins, labels=labels).fillna(labels[0]) 它给了我分数范围,但不是整数。所以,我看到了: DVScores 0

我正在测试这个代码

labels = pd.interval_range(start=0, freq=1, end=55)
bins = pd.interval_range(start=0, freq=1, end=55)
dataset['DVScores'] = pd.cut(dataset['DV'], bins=bins, labels=labels).fillna(labels[0])
它给了我分数范围,但不是整数。所以,我看到了:

        DVScores  
0         (10, 11]  
1           (2, 3]  
2           (1, 2]  
3           (0, 1]  
4         (13, 14]  
我想把它转换成这样的格式:

11
3
2
1
14
bins = [0, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25, 5.5, 5.75, 6, 6.25, 6.5, 6.75, 7, 7.25, 7.5, 7.75, 8, 8.25, 8.5, 8.75, 9, 9.25, 9.5, 9.75, 10, np.inf]
bins= pd.interval_range(start=0, freq=1, end=55)
我看了看中间和右边,但我不能让它只给我一个数字。我相信,如果你硬编码,像这样:

11
3
2
1
14
bins = [0, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25, 5.5, 5.75, 6, 6.25, 6.5, 6.75, 7, 7.25, 7.5, 7.75, 8, 8.25, 8.5, 8.75, 9, 9.25, 9.5, 9.75, 10, np.inf]
bins= pd.interval_range(start=0, freq=1, end=55)
我有很多这样的东西,它们都有点不同,所以我希望能做得更像这样:

11
3
2
1
14
bins = [0, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25, 5.5, 5.75, 6, 6.25, 6.5, 6.75, 7, 7.25, 7.5, 7.75, 8, 8.25, 8.5, 8.75, 9, 9.25, 9.5, 9.75, 10, np.inf]
bins= pd.interval_range(start=0, freq=1, end=55)

我认为你正在寻找正确的价值的垃圾桶。您可以通过以下方式检索:

dataset['DVScores'].apply(lambda x: x.right)
您是否有dataset['DV']的示例?