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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。