由于数据库问题,将dtype('O')转换为dtype('< M8 [ns]') [英] Converting dtype('O') to dtype('<M8[ns]') because of database problem
本文介绍了由于数据库问题,将dtype('O')转换为dtype('< M8 [ns]')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的timestamp
列有1000个数据(常规的mySQL时间戳),我将其分为两个,分别称为data1
和data2
I have 1000 data with timestamp
column (regular mySQL timestamp), and I split this into two, called data1
and data2
,
`data1['timestamp'].dtype`
dtype('<M8[ns]')
可能是因为一两个条目已损坏,所以
Probably because one or two entry is broken, so
`data2['timestamp'].dtype`
dtype('O')
我需要成为dtype('<M8[ns]')
以便进行进一步分析
and I need to data2['timestamp'].dtype
to be dtype('<M8[ns]')
to do further analysis
推荐答案
您可以使用 to_datetime
,参数为errors='coerce'
:
data2['timestamp'] = pd.to_datetime(data2['timestamp'], errors='coerce')
这篇关于由于数据库问题,将dtype('O')转换为dtype('< M8 [ns]')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文