Python Pandas——檢查設定為開放的間隔是否為空
要檢查將間隔設定為開放時是否為空,請使用 interval.is_empty 屬性。首先,匯入必需的庫——
import pandas as pd
使用值為“neither”的“closed”引數開啟間隔集。開放間隔(在數學中用方括號表示)不包含其端點,即開放間隔 [0, 5] 的特徵是條件 0 < x < 5
interval = pd.Interval(0, 0, closed='neither')
顯示間隔
print("Interval...\n",interval)當間隔開放時檢查其是否為空,即無端點。不包含任何點的間隔為空
print("\nIs Interval empty? \n",interval.is_empty)
示例
以下是程式碼
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(0, 0, closed='neither')
# display the interval
print("Interval...\n",interval)
# display the interval length
print("\nInterval length...\n",interval.length)
# check whether interval is empty when it is open i.e. no endpoints
# An Interval that does not contain any points is empty:
print("\nIs Interval empty? \n",interval.is_empty)輸出
程式碼如下
Interval... (0, 0) Interval length... 0 Is Interval empty? True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP