如何在dataframe python中找到不是时间戳的数据?

问题描述 投票:1回答:2

这是时间戳列:

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

+我认为这可能是db中的一个解析问题。

python dataframe timestamp
2个回答
2
投票

我相信您需要创建默认索引以防止reset_index重复,然后调用drop_duplicates

ds['TIME'].reset_index(drop=True).drop_duplicates()

如果可能多列:

ds.reset_index(drop=True).drop_duplicates(subset=['TIME'])

1
投票

尝试使用内置的type()函数。我不知道这是否是正确的方法,但很简单:

if 'datetime' in str(type(ds)):
    print('Is a datetime format')
© www.soinside.com 2019 - 2024. All rights reserved.