如何在dataframepython中找到非时间戳数据?

2024-04-23 06:56:39 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是时间戳列:

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'

所以我试着找到一个数据类型不同的列,比如under code,但没有成功。你知道吗

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

+我认为这可能是db中的解析问题。你知道吗


Tags: instancesdatadatetimetimetype错误时间ds
2条回答

我相信您需要为防止被^{}复制创建默认索引,然后调用^{}

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

相关问题 更多 >