Python| Pandas Timedelta.components
Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas 就是其中之一,它使导入和分析数据变得更加容易。
Timedelta 是datetime.timedelta
的子类,行为方式类似。它是 python 的datetime.timedelta
的 pandas 等价物,在大多数情况下可以与它互换。 Timedelta.components
中的pandas.Timedelta
属性用于返回类似 NamedTuple 的组件。
Syntax: Timedelta.components
Parameters: None
Returns: return a Components NamedTuple-like
代码#1:
# importing pandas as pd
import pandas as pd
# Create the Timedelta object
td = pd.Timedelta('3 days 06:05:01.000030')
# Print the Timedelta object
print(td)
print(td.components)
3 days 06:05:01.000030
Components(days=3, hours=6, minutes=5, seconds=1, milliseconds=0, microseconds=30, nanoseconds=0)
代码#2:
# importing pandas as pd
import pandas as pd
# Create the Timedelta object
td = pd.Timedelta('1 days 7 hours')
# Print the Timedelta object
print(td)
print(td.components)
1 days 07:00:00
Components(days=1, hours=7, minutes=0, seconds=0, milliseconds=0, microseconds=0, nanoseconds=0)
代码#3:
# importing pandas as pd
import pandas as pd
import datetime
# Create the Timedelta object
td = pd.Timedelta(datetime.timedelta(days = 3, hours = 7, seconds = 8))
# Print the Timedelta object
print(td)
print(td.components)
3 days 07:00:08
Components(days=3, hours=7, minutes=0, seconds=8, milliseconds=0, microseconds=0, nanoseconds=0)