Python Pandas Timestamp.to_datetime64
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas Timestamp.to_datetime64()函数为给定的Timestamp对象返回一个精度为’ns’的numpy.datetime64对象。
语法 :
Timestamp.to_datetime64()
参数:无
返回: numpy.datetime64对象
示例#1:使用Timestamp.to_datetime64()函数为给定的Timestamp对象返回一个numpy.datetime64对象。
# 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.to_datetime64()函数来为给定的Timestamp返回一个numpy.datetime64对象。
# return numpy.datetime64 object
ts.to_datetime64()
输出 :

正如我们在输出中看到的,Timestamp.to_datetime64()函数为给定的Timestamp对象返回了一个numpy.datetime64对象,精度为’ns’。
示例#2:使用Timestamp.to_datetime64()函数为给定的Timestamp对象返回numpy.datetime64对象。
# 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.to_datetime64()函数来为给定的Timestamp返回一个numpy.datetime64对象。
# return numpy.datetime64 object
ts.to_datetime64()
输出 :

正如我们在输出中看到的,Timestamp.to_datetime64()函数为给定的Timestamp对象返回了一个numpy.datetime64对象,精度为’ns’。
极客教程