Python Pandas - 获取区间的左边界
要获得区间的左边界,请使用该interval.left属性。首先,导入所需的库-
import pandas as pd
使用时间戳作为边界来创建时间间隔。使用值为“left”的“closed”参数设置的闭合区间。获取区间的左边界
interval = pd.Interval(pd.Timestamp('2020-01-01 00:00:00'), pd.Timestamp('2021-01-01 00:00:00'), closed='left')
显示间隔
print("Interval...\n",interval)
获取左边界
print("\nThe left bound for the Interval...\n",interval.left)
示例
以下是代码
import pandas as pd #使用时间戳作为边界来创建时间间隔 # Closed interval set using the "closed" 带值的参数 "left" #获取区间的左边界 interval = pd.Interval(pd.Timestamp('2020-01-01 00:00:00'), pd.Timestamp('2021-01-01 00:00:00'), closed='left') #显示间隔 print("Interval...\n",interval) #显示间隔 length print("\nInterval length...\n",interval.length) #左边界 print("\nThe left bound for the Interval...\n",interval.left)输出结果
这将产生以下代码
Interval... [2020-01-01, 2021-01-01) Interval length... 366 days 00:00:00 The left bound for the Interval... 2020-01-01 00:00:00