Python Pandas - 使用整数输入从 Timedelta 对象返回微秒
要从Timedelta对象返回纳秒,请使用timedelta.microseconds属性。首先,导入所需的库-
import pandas as pd
TimeDeltas是Python的标准日期时间库,使用不同的表示形式timedelta。使用单位“us”为微秒设置整数输入。创建一个Timedelta对象
timedelta = pd.Timedelta(55, unit ='us')
显示时间增量
print("Timedelta...\n", timedelta)
返回微秒值
timedelta.microseconds
示例
以下是代码
import pandas as pd #TimeDeltas是Python的标准日期时间库,使用不同的表示形式timedelta's # set integer input for microseconds using unit 'us' #创建一个Timedelta对象 timedelta = pd.Timedelta(55, unit ='us') #显示时间增量 print("Timedelta...\n", timedelta) #返回微秒值 res = timedelta.microseconds #显示微秒 print("\nTimedelta (microseconds value)...\n", res)输出结果
这将产生以下代码
Timedelta... 0 days 00:00:00.055000 Timedelta (microseconds value)... 55