1

Here is the timestamp column:

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
         .
         .

And I tried merge and faced the following error.

TypeError: '<' not supported between instances of 'datetime.datetime' and 'int'

So I tried to find a column with a different data type like under code, but it didn't worked.

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 

how can i solve this problem?

I would be grateful if you give me some good advice.

this is what i try.

raw_data = pd.merge_ordered(ds,ds2)
#ds2 is similar data like ds

+I think it might be a parse problem in db.

2 Answers 2

2

I believe you need create default index for prevent duplicated by reset_index and then call drop_duplicates:

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

If possible multiple columns:

ds.reset_index(drop=True).drop_duplicates(subset=['TIME'])
Sign up to request clarification or add additional context in comments.

8 Comments

Thank you for giving me a good comparison. Still, the errors that appear above are not resolved. Is there a way to resolve this error?
i also didn't worked. and i check all data type using type(), all data is same(<class 'pandas._libs.tslibs.timestamps.Timestamp'>). it so hard to solve it ㅜㅜ
in my real data it has not duplicate date(check ds.drop_duplicate()). TypeError: '<' not supported between instances of 'datetime.datetime' and 'int' <--Does this error occur when the same data exists?
@송준석 - Do youi think ds['TIME'].drop_duplicates() ? If failed, try ds['TIME'].reset_index(drop=True).drop_duplicates()
i think it didn't worked. if you give your email, i sen real data. Looking at the actual data, the problem seems to be clearer.
|
1

Try to use built-in type() function. I don't know if this is a correct way, but is simple:

if 'datetime' in str(type(ds)):
    print('Is a datetime format')

1 Comment

in case of my data, str(type(ds)) 's result is "<class 'pandas._libs.tslibs.timestamps.Timestamp'>" so i use upper code using 'timestamps' but it also didn't worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.