Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将对象类型转换为datetime64?_Python_Datetime_Object - Fatal编程技术网

Python 如何将对象类型转换为datetime64?

Python 如何将对象类型转换为datetime64?,python,datetime,object,Python,Datetime,Object,当我看到数据类型时,它似乎是object,但我无法将其转换为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 我已经试过了,但不起作用 df['Data e Hora In

当我看到数据类型时,它似乎是object,但我无法将其转换为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
我已经试过了,但不起作用

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')
照办

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

我也试过了,但出现了一个错误:`TypeError:不能转换为datetime`@bonaqua您遇到了什么错误?请更新您的问题,并在可能的情况下发布完整的回溯peerror:无法转换为datetime@bonaqua除了显示的代码之外,您还做了其他事情吗?错误表明您的数据是时间,而不是日期,但您的示例似乎与我只是导入库、读取excel然后这样做(以避免中间出现任何其他错误)相矛盾