Python Pandas - 获得区间右侧边界
要获得区间右侧边界,请使用 interval.right 属性。首先,导入必需的库 −
import pandas as pd
使用时间戳作为边界来创建时间间隔。闭区间使用 "closed" 参数,值为 "right" −
interval = pd.Interval(pd.Timestamp('2020-01-01 00:00:00'), pd.Timestamp('2021-01-01 00:00:00'), closed='left')
获取右侧边界 −
print("\nThe right bound for the Interval...\n",interval.right)
示例
以下为代码 −
import pandas as pd # Use Timestamps as the bounds to create a time interval # Closed interval set using the "closed" parameter with value "right" 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) # get the right bound print("\nThe right bound for the Interval...\n",interval.right)
输出
这将生成以下代码 −
Interval... [2020-01-01, 2021-01-01) Interval length... 366 days 00:00:00 The right bound for the Interval... 2021-01-01 00:00:00
广告