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 # Use Timestamps as the bounds to create a time interval # Closed interval set using the "closed" parameter with value "left" # Get the left bound for the interval interval = pd.Interval(pd.Timestamp('2020-01-01 00:00:00'), pd.Timestamp('2021-01-01 00:00:00'), closed='left') # display the interval print("Interval...\n",interval) # display the interval length print("\nInterval length...\n",interval.length) # the left bound 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
广告