Để trả về số nano giây trong đối tượng DateOffset đã cho, hãy sử dụng thuộc tính offset.nanos trong Pandas.
Đầu tiên, hãy nhập các thư viện được yêu cầu -
from pandas.tseries.frequencies import to_offset import pandas as pd
Đặt đối tượng dấu thời gian trong Pandas -
timestamp = pd.Timestamp('2021-08-30 03:08:02.000045')
Tạo DateOffset. Chúng tôi đang tăng số ngày ở đây bằng tần suất "D" -
offset = to_offset("5D") Hiển thị Dấu thời gian đã cập nhật -
print("\nUpdated Timestamp...\n",timestamp + offset)
Trả lại nano giây trong đối tượng DateOffset đã cho -
print("\nThe number of nanoseconds in the DateOffset object..\n", offset.nanos) Ví dụ
Sau đây là mã -
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) Đầu ra
Điều này sẽ tạo ra mã sau -
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