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