我正在尝试将包含0到100范围内的年龄的数据帧列绑定.
当我尝试使用bin来包含零年龄时,它不起作用.
这是一个使用包含我的数据范围的列表的演示:
pd.cut(pd.Series(range(101)), [0, 24, 49, 74, 100])
范围中的零值从切割返回NaN.
有什么方法吗?
解决方法:
IIUC你需要将include_lowest参数设置为True.从docs开始:
include_lowest : bool
Whether the first interval should be left-inclusive or not.
对于你的情况:
pd.cut(pd.Series(range(101)), [0,24,49,74,100], include_lowest=True)
In [148]: pd.cut(pd.Series(range(101)), [0,24,49,74,100], include_lowest=True).head(10)
Out[148]:
0 [0, 24]
1 [0, 24]
2 [0, 24]
3 [0, 24]
4 [0, 24]
5 [0, 24]
6 [0, 24]
7 [0, 24]
8 [0, 24]
9 [0, 24]
dtype: category
Categories (4, object): [[0, 24] < (24, 49] < (49, 74] < (74, 100]]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。