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