Python Pandas - 獲取間隔的長度
若要獲取間隔的長度,請使用 interval.length 屬性。首先,匯入必需的庫 -
import pandas as pd
使用值"neither"的"closed"引數設定開放區間。開放區間(在數學中用方括號表示)不包含其端點,即開放區間 [0, 5] 的特徵是條件 0 < x < 5
interval = pd.Interval(5, 20, closed='neither')
顯示間隔長度
print("\nInterval length...\n",interval.length)
示例
以下為程式碼
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)輸出
將生成以下程式碼
Interval... (5, 20) The left bound for the Interval... 5 The right bound for the Interval... 20 Interval length... 15
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP