简体   繁体   中英

How to convert object type to datetime64?

When I see the dtype, it seems to be object, but I cannot convert it to datetime64

0    2017-11-29 17:14:00
1    2017-02-15 15:35:00
2    2018-10-18 08:02:00
3    2017-06-22 09:25:00
4    2017-09-21 11:12:00
Name: Data e Hora Indução Anestesica, dtype: object

I have already tried this, but it does not work.

df['Data e Hora Indução Anestesica'].astype(str).astype(int)
hg = df['Data e Hora Indução Anestesica'].astype(str).str.zfill(6)
df['Data e Hora Indução Anestesica'] = pd.to_datetime(hg, format='%Y/%m/%d%H%M%S')

Just do

df['Data e Hora Indução Anestesica'] = pd.to_datetime(df['Data e Hora Indução Anestesica'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM