Python Pandas - 返回给定 DateOffset 对象中的纳秒数
要返回给定DateOffset对象中的纳秒数,请使用offset.nanosPandas中的属性。
首先,导入所需的库-
from pandas.tseries.frequencies import to_offset import pandas as pd
在Pandas中设置时间戳对象-
timestamp = pd.Timestamp('2021-08-30 03:08:02.000045')创建日期偏移量。我们在这里使用“D”频率增加天数-
offset = to_offset("5D")显示更新的时间戳-
print("\nUpdated Timestamp...\n",timestamp + offset)返回给定DateOffset对象中的纳秒-
print("\nThe number of nanoseconds in the DateOffset object..\n", offset.nanos)示例
以下是代码-
from pandas.tseries.frequencies import to_offset
import pandas as pd
#在Pandas中设置时间戳对象
timestamp = pd.Timestamp('2021-08-30 03:08:02.000045')
#显示时间戳
print("Timestamp...\n",timestamp)
#创建日期偏移
# We are incrementing the days here using the "D" frequency
offset = to_offset("5D")
#显示日期偏移
print("\nDateOffset...\n",offset)
#显示更新的时间戳
print("\nUpdated Timestamp...\n",timestamp + offset)
#返回给定DateOffset对象中的纳秒
print("\nThe number of nanoseconds in the DateOffset object..\n", offset.nanos)输出结果这将产生以下代码-
Timestamp... 2021-08-30 03:08:02.000045 DateOffset... <5 * Days> Updated Timestamp... 2021-09-04 03:08:02.000045 The number of nanoseconds in the DateOffset object.. 432000000000000