Pandas Series 字符串类型转为datetime类型
s = pd.Series(['2017-11-24 00:00:00','2017-11-25 00:00:00','2017-11-26 00:00:00'])
s
#0 2017-11-24 00:00:00
#1 2017-11-25 00:00:00
#2 2017-11-26 00:00:00
#dtype: object
ts = pd.to_datetime(s)
ts
#0 2017-11-24
#1 2017-11-25
#2 2017-11-26
#dtype: datetime64[ns]
字符串对象转Timestamp对象
p3=pd.Timestamp("2017-6-19 9:13:45")
print("type of p3:",type(p3))
print(p3)
输出
('type of p3:', )
2017-06-19 09:13:45
Timestamp对象转datetime对象
p3=pd.Timestamp("2017-6-19 9:13:45")
输出
p3.to_pydatetime()
Out[12]: datetime.datetime(2017, 6, 19, 9, 13, 45)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)