Python Pandas - 返回纳秒单位的 numpy timedelta64 数组标量视图
若要在纳秒单位中返回 numpy timedelta64 数组标量视图,请在 Pandas 中使用timedelta.asm8 属性。
首先,导入所需的库
import pandas as pd
示例
以下为代码
import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('10 min 20 s') # display the Timedelta print("Timedelta...\n", timedelta) # getting the timedelta64 in nanoseconds res = timedelta.asm8 # display the timedelta64 print("\nTimedelta64 array scalar view...\n", res)
输出
将生成以下代码
Timedelta... 0 days 00:10:20 Timedelta64 array scalar view... 620000000000 nanoseconds
广告