这是时间戳列:
TIME
2018-03-02 11:57:37
2018-03-12 10:36:16
2018-03-29 12:02:21
2018-03-23 16:37:08
2018-03-09 22:22:28
.
.
我尝试合并并遇到以下错误。
TypeError: '<' not supported between instances of 'datetime.datetime' and 'int'
所以我试图找到一个数据类型不同的列,就像在代码下一样,但它没有奏效。
for i in range(len(ds)):
if type(ds['TIME'].loc[i]) != type(ds['TIME'].loc[1]) :
ds = ds.drop(i)
# type(ds['TIME'].loc[1]) was confirmed that it was a timestamp type
我该如何解决这个问题?
如果您给我一些好的建议,我将不胜感激。
这就是我尝试的。
raw_data = pd.merge_ordered(ds,ds2)
#ds2 is similar data like ds
+我认为这可能是数据库中的解析问题。
我相信
您需要创建默认索引以防止reset_index
重复,然后调用drop_duplicates
:
ds['TIME'].reset_index(drop=True).drop_duplicates()
如果可能,多列:
ds.reset_index(drop=True).drop_duplicates(subset=['TIME'])
尝试使用内置的type((函数。我不知道这是否是正确的方法,但很简单:
if 'datetime' in str(type(ds)):
print('Is a datetime format')