Python Pandas - 从 Timedelta 对象返回微秒
要从 Timedelta 对象中返回微秒,请使用 timedelta.microseconds 属性。首先,导入所需的库 -
import pandas as pd
TimeDeltas 是 Python 标准 datetime 库,使用不同的表示形式 timedelta。创建一个 Timedelta 对象
timedelta = pd.Timedelta('7 days 20 min 15 s 35 ms')
返回微秒值
timedelta.microseconds
示例
代码如下所示
import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('7 days 20 min 15 s 35 ms') # display the Timedelta print("Timedelta...\n", timedelta) # return the microseconds value res = timedelta.microseconds # display the microseconds print("\nTimedelta (microseconds value)...\n", res)
输出
将生成以下代码
Timedelta... 7 days 00:20:15.035000 Timedelta (microseconds value)... 35000
广告