Python Pandas - 使用字符串输入从 Timedelta 对象返回微秒
要从 Timedelta 对象返回纳秒,请使用 timedelta.microseconds 属性。首先,导入必需的库 −
import pandas as pd
TimeDeltas 是 Python 的标准 datetime 库使用 Unit“us”中用于微秒的不同的表示 timedelta。设置字符串输入为微秒。创建一个 Timedelta 对象
timedelta = pd.Timedelta('12 min 40 us')
显示 Timedelta
print("Timedelta...\n", timedelta)返回微秒值
timedelta.microseconds
示例
以下为代码
import pandas as pd
# TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s
# set string input for microseconds using unit 'us'
# create a Timedelta object
timedelta = pd.Timedelta('12 min 40 us')
# Display the Timedelta:
print("Timedelta...\n", timedelta)
# return the microseconds value
res = timedelta.microseconds
# display the microseconds
print("\nTimedelta (microseconds value)...\n", res)输出
将生成以下代码
Timedelta... 0 days 00:12:00.040000 Timedelta (microseconds value)... 40000
广告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP