Python Pandas - 获取区间的正确界限
要获得区间的正确界限,请使用interval.right 属性。首先,导入所需的库 -
import pandas as pd
使用时间戳作为边界来创建时间间隔。使用值为“right”的“closed”参数设置的闭合区间 -
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" 带值的参数 "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
以上是 Python Pandas - 获取区间的正确界限 的全部内容, 来源链接: utcz.com/z/322631.html