Reputation: 61
I've got data in excel, one sheet has dates as columns, the other - as rows. Using pd.read_excel I get them as dataframes. The type of one (Data1) is datetime.datetime, the other (Data2) is timestamp.
I want to do
Data1[Data1.index<Data2.columns[-1]]
this returns an error
TypeError: '<=' not supported between instances of 'datetime.time' and 'Timestamp'
I tried doing
datetime(Data2.columns[-1].year,Data2.columns[-1].month,Data2.columns[-1].day)
instead of
Data2.columns[-1]
the error changes to
TypeError: '<=' not supported between instances of 'datetime.time' and 'datetime.datetime'
EDIT
this seems to be the crux of the issue:
Data1[Data1.index<Data1.index[3]]
returns
TypeError: '<' not supported between instances of 'datetime.time' and 'datetime.datetime'
Data type for Data1.index is datetime.time.
Upvotes: 0
Views: 124
Reputation: 25564
Make sure to compare apples with apples. Either compare full datetime (date and time component) or only one of each. Ex:
from datetime import datetime, timedelta
import pandas as pd
# date and time:
pd.Timestamp('now') >= datetime.now() + timedelta(hours=1)
# False
# time only:
pd.Timestamp('now').time() >= (datetime.now() + timedelta(hours=1)).time()
# False
# date only:
pd.Timestamp('now').date() >= (datetime.now() + timedelta(hours=1)).date()
# True
as opposed to e.g.
pd.Timestamp('now').time() >= (datetime.now() + timedelta(hours=1))
...will throw
TypeError: '>=' not supported between instances of 'datetime.time' and 'datetime.datetime'
Upvotes: 1