Python Pandas - 檢查區間是否在右側開啟
要檢查區間是否在右側開啟,請使用 interval.open_right 屬性。首先,匯入所需的庫 -
import pandas as pd
使用值設為 "neither" 的 "closed" 引數設定開放區間。開放區間(在數學中用方括號表示)不包含其端點,即開放區間 [0, 5] 的特點是條件 0 < x < 5
interval = pd.Interval(5, 20, closed='neither')
顯示區間
print("Interval...\n",interval)
檢查區間是否在右側開啟
print("\nCheck if the interval is open on the right side...\n",interval.open_right)示例
以下是程式碼
import pandas as pd
# Open interval set using the "closed" parameter with value "neither"
# An open interval (in mathematics denoted by square brackets) does not contains its endpoints,
# i.e. the open interval [0, 5] is characterized by the conditions 0 < x < 5.
interval = pd.Interval(5, 20, closed='neither')
# display the interval
print("Interval...\n",interval)
# the left bound
print("\nThe left bound for the Interval...\n",interval.left)
# the right bound
print("\nThe right bound for the Interval...\n",interval.right)
# display the interval length
print("\nInterval length...\n",interval.length)
# check whether the interval is open on the right side
print("\nCheck if the interval is open on the right side...\n",interval.open_right)輸出
這會生成以下程式碼
Interval... (5, 20) The left bound for the Interval... 5 The right bound for the Interval... 20 Interval length... 15 Check if the interval is open on the right side... True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP