要将Timestamp对象转换为本机Python日期时间对象,请使用该方法。timestamp.to_pydatetime()
首先,导入所需的库-
import pandas as pd在Pandas中创建时间戳对象
timestamp = pd.Timestamp(2021-09-11T13:12:34.261811)将时间戳转换为本机Python日期时间对象
timestamp.to_pydatetime()以下是代码
import pandas as pd #在Pandas中设置时间戳对象 timestamp = pd.Timestamp(2021-09-11T13:12:34.261811) #显示时间戳 print("Timestamp...\n", timestamp) #将时间戳转换为本机Python日期时间对象 print("\nConvert Timestamp...\n", timestamp.to_pydatetime())输出结果这将产生以下代码
Timestamp... 2021-09-11 13:12:34.261811 Convert Timestamp... 2021-09-11 13:12:34.261811