Python Pandas - 检查区间是否在左侧、右侧、两者或两者都不闭合
要检查区间是否在左侧、右侧、两者或两者都不闭合,请使用该interval.closed属性。
首先,导入所需的库-
import pandas as pd
使用值为“both”的“closed”参数设置的封闭区间。一个闭区间(在数学中用方括号表示)包含它的端点,#即闭区间[0,5]的特征在于条件0<=x<=5
interval = pd.Interval(left=0, right=20, closed='both')
显示间隔
print("Interval...\n",interval)检查区间是否在左侧、右侧、两者或两者都不闭合
print("\nChecking for the type of Interval...\n",interval.closed)示例
以下是代码
import pandas as pd
# Closed interval set using the "closed" 带值的参数 "both"
#Aclosedinterval(inmathematicsdenotedbysquarebrackets)containsitsendpoints,
# i.e. the closed interval [0, 5] is characterized by the conditions 0 <= x <= 5.
interval = pd.Interval(left=0, right=20, closed='both')
#displaytheinterval
print("Interval...\n",interval)
#checkwhethertheintervalisclosedontheleft-side,right-side,bothorneither
print("\nChecking for the type of Interval...\n",interval.closed)
#checkfortheexistenceofanelementinanInterval
#Thisshowsthatclosed=bothcontainsitsendpoints
print("\nThe left-most element exists in the Interval? = \n",0 in interval)
print("\nThe right-most element exists in the Interval? = \n",20 in interval)输出结果这将产生以下代码
Interval... [0, 20] Checking for the type of Interval... both
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便