Pandas Series.between(~) 方法返回一个布尔值向量,指示 Series 中的每个元素是否在提供的范围内。 NaN 值被视为 False 。
参数
1. left | scalar
下边界。
2. right | scalar
上边界。
3. inclusive | string | optional
指定left 和right 边界是否应包含在内。默认为 "both" 。其他选项包括 "neither" 、 "left" 、 "right" 。
返回值
一个新的布尔值系列,指示每个元素是否位于 left 和 right 边界之间。
例子
基本用法
要检查系列中的元素是否位于 3 和 5 之间(包括两端):
import pandas as pd
s = pd.Series([1,2,3,4,5,6])
s.between(3,5)
0 False
1 False
2 True
3 True
4 True
5 False
包括的
要检查系列中的元素是否位于 3 和 5 之间(两端都不包括):
s = pd.Series([1,2,3,4,5,6])
s.between(3, 5, inclusive="neither")
0 False
1 False
2 False
3 True
4 False
5 False
注意
请注意 3 和 5 现在如何返回 False,因为我们使用 inclusive="neither" 排除左右边界。
NaN
要检查系列中的元素是否位于 3 和 5 之间(包括两端):
s = pd.Series([1,2,3,np.NaN,5,6])
s.between(3,5)
0 False
1 False
2 True
3 False
4 True
5 False
注意
请注意,np.NaN 的计算结果为 False
相关用法
- Python Pandas Series str extractall方法用法及代码示例
- Python Pandas Series str split方法用法及代码示例
- Python Pandas Series to_list方法用法及代码示例
- Python Pandas Series str center方法用法及代码示例
- Python Pandas Series str pad方法用法及代码示例
- Python Pandas Series map方法用法及代码示例
- Python Pandas Series hasnans属性用法及代码示例
- Python Pandas Series is_monotonic属性用法及代码示例
- Python Pandas Series str extract方法用法及代码示例
- Python Pandas Series string contains方法用法及代码示例
- Python Pandas Series to_frame方法用法及代码示例
- Python Pandas Series zfill方法用法及代码示例
- Python Pandas Series argmax方法用法及代码示例
- Python Pandas Series str replace方法用法及代码示例
- Python Pandas Series str len方法用法及代码示例
- Python Pandas Series str lower方法用法及代码示例
- Python Pandas Series is_monotonic_increasing属性用法及代码示例
- Python Pandas Series str strip方法用法及代码示例
- Python Pandas Series is_unique属性用法及代码示例
- Python Pandas Series str rstrip方法用法及代码示例
- Python Pandas Series str lstrip方法用法及代码示例
- Python Pandas Series argmin方法用法及代码示例
- Python Pandas Series value_counts方法用法及代码示例
- Python Pandas Series is_monotonic_decreasing属性用法及代码示例
- Python Pandas Series.cumsum()用法及代码示例
注:本文由纯净天空筛选整理自Arthur Yanagisawa大神的英文原创作品 Pandas Series | between method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
