Pandas - 将时间戳对象转换为本机 Python 日期时间对象
要将时间戳对象转换为本机 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
# set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-09-11T13:12:34.261811')
# display the Timestamp
print("Timestamp...\n", timestamp)
# convert timestamp to native Python datetime object
print("\nConvert Timestamp...\n", timestamp.to_pydatetime())输出
将生成以下代码
Timestamp... 2021-09-11 13:12:34.261811 Convert Timestamp... 2021-09-11 13:12:34.261811
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP