Python Pandas - 返回给定的 DateOffset 对象中的纳秒数
若要返回给定 DateOffset 对象中的纳秒数,请在 Pandas 中使用 offset.nanos 属性。
首先,导入必要的库 −
from pandas.tseries.frequencies import to_offset import pandas as pd
在 Pandas 中设置时间戳对象 −
timestamp = pd.Timestamp('2021-08-30 03:08:02.000045')
创建一个 DateOffset。我们将使用“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
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-08-30 03:08:02.000045')
# Display the Timestamp
print("Timestamp...\n",timestamp)
# Create the DateOffset
# We are incrementing the days here using the "D" frequency
offset = to_offset("5D")
# Display the DateOffset
print("\nDateOffset...\n",offset)
# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + offset)
# return the nanoseconds in the given DateOffset object
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP