Python Pandas - 从 Timedelta 对象返回纳秒
要从 Timedelta 返回微秒,请使用 timedelta.nanoseconds 属性。首先,导入必需的库 −
import pandas as pd
TimeDeltas 是 Python 的标准 datetime 库,它使用不同的表示方法。创建一个 Timedelta 对象
timedelta = pd.Timedelta('4 days 10 min 25 s 15 ms 33 ns')
显示 Timedelta
print("Timedelta...\n", timedelta)
返回纳秒值
timedelta.nanoseconds
示例
以下是代码
import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('4 days 10 min 25 s 15 ms 33 ns') # display the Timedelta print("Timedelta...\n", timedelta) # return the nanoseconds value res = timedelta.nanoseconds # display the nanoseconds print("\nTimedelta (nanoseconds value)...\n", res)
输出
这将生成以下代码
Timedelta... 4 days 00:10:25.015000033 Timedelta (nanoseconds value)... 33
广告