Python是进行数据分析的一种出色语言,主要是因为以数据为中心的python软件包具有奇妙的生态系统。 Pandas是其中的一种,使导入和分析数据更加容易。
Pandas Timestamp.timetuple()函数返回给定Timestamp对象的时间元组。返回的元组包含从年,月到小时和秒的值。时间元组与time.localtime()兼容。
用法:Timestamp.timetuple()
参数:没有
返回:时间元组
范例1:采用Timestamp.timetuple()函数为给定的Timestamp对象返回一个时间元组。
# importing pandas as pd
import pandas as pd
# Create the Timestamp object
ts = pd.Timestamp(year = 2011, month = 11, day = 21,
hour = 10, second = 49, tz = 'US/Central')
# Print the Timestamp object
print(ts)
输出:
现在我们将使用Timestamp.timetuple()函数返回一个时间元组。
# return time tuple
ts.timetuple()
输出:
正如我们在输出中看到的,Timestamp.timetuple()函数已为给定的Timestamp对象返回一个元组,其中包含诸如年,月,日等值。
范例2:采用Timestamp.timetuple()函数为给定的Timestamp对象返回一个时间元组。
# importing pandas as pd
import pandas as pd
# Create the Timestamp object
ts = pd.Timestamp(year = 2009, month = 5, day = 31,
hour = 4, second = 49, tz = 'Europe/Berlin')
# Print the Timestamp object
print(ts)
输出:
现在我们将使用Timestamp.timetuple()函数返回一个时间元组。
# return time tuple
ts.timetuple()
输出:
正如我们在输出中看到的,Timestamp.timetuple()函数已为给定的Timestamp对象返回一个元组,其中包含诸如年,月,日等值。