pandas.cut 函数在假定为 0 时给了我负值
我很困惑为什么我的 pd.cut 函数给我的起始间隔是负值。 我已剪切的列的最小值为 0。因此,我希望 pd.cut 函数抛出的第一个区间为 (0,18),而不是 (-0.18,18)。
我已将精度设置更改为 0。但是,这只会使我的起始间隔变为 (-0.0,18)。
当我解析到 pd.cut 函数中的列是整数时,为什么我的间隔全部是浮点数?
感谢所有帮助。谢谢。
I am perplexed as to why my pd.cut function gave me the starting interval that is a negative value.
The column that I have cut on, has a minimum value of 0. Hence, I expect my pd.cut function to throw out my first interval to be (0,18) instead of (-0.18,18).
I have changed the precision setting to be 0. However, that just makes my starting interval to be (-0.0,18).
And why is my intervals all in float when the column I've parsed into my pd.cut function is in integers?
Would appreciate all help. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中所解释的,您要求
cut
自动为您定义垃圾箱,默认情况下它们是等宽的,这意味着可以有负边界。如果您希望保留自动分箱,您可以随后手动修改间隔。这是仅第一个间隔“不正确”的情况的示例,使用
cat.rename_categories
:输出:
As explained in the comments, you asked
cut
to define the bins automatically for you, by default they are equal width, which mean having a negative bound is possible.If you wish to keep the automatic binning, you can modify the intervals manually afterwards. Here is an example in case of only the first interval that is "incorrect", using
cat.rename_categories
:output: