Python Pandas - 检查给定的 DateOffset 是否已锚定
要检查给定的DateOffset是否已锚定,请使用Pandas中的方法。首先,导入所需的库-offset.is_anchored()
from pandas.tseries.frequencies import to_offset import pandas as pd
在Pandas中设置时间戳对象-
timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')创建日期偏移量。我们在周二使用锚定偏移,即每周频率-
offset = to_offset("W-TUE")显示更新的时间戳-
print("\nUpdated Timestamp...\n",timestamp + offset)检查DateOffset是否已锚定-
print("\nCheck whether the DateOffset is anchored...\n", offset.is_anchored())示例
以下是代码-
from pandas.tseries.frequencies import to_offset
import pandas as pd
#在Pandas中设置时间戳对象
timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')
#显示时间戳
print("Timestamp...\n",timestamp)
#创建日期偏移
#我们在周二使用锚定偏移,即每周频率
offset = to_offset("W-TUE")
#显示日期偏移
print("\nDateOffset...\n",offset)
#显示更新的时间戳
print("\nUpdated Timestamp...\n",timestamp + offset)
#检查DateOffset是否被锚定
print("\nCheck whether the DateOffset is anchored...\n", offset.is_anchored())输出结果这将产生以下代码-
Timestamp... 2021-09-26 03:25:02.000045 DateOffset... <Week: weekday=1> Updated Timestamp... 2021-09-28 03:25:02.000045 Check whether the DateOffset is anchored... True
热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练