Python Pandas - 檢查區間是否在左側開放
要檢查區間是否在左側開啟,請使用 interval.open_left 屬性。首先,匯入所需的庫 -
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 left side...\n",interval.open_left)示例
以下是程式碼
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 left side
print("\nCheck if the interval is open on the left side...\n",interval.open_left)輸出
這將生成以下程式碼
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 left side... True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP