Reputation: 55
What is the easiest way to get rid of this simple error:
'>' not supported between instances of 'float' and 'str'.
Some of the articles look really complex to solve this, but in my opinion, there should be an easy fix. Like putting currentTime==(str(currentTime)).
Other things I attempted are at the bottom. My code :
df=pd.read_csv(file_name, header=None)
last3Rows=df.iloc[-3:]
for i in range(3):
lastRow = df.iloc[i]
tradeTime=lastRow[4]
currentTime=datetime.datetime.now().timestamp()
print (currentTime)
print(type(currentTime))
print (tradeTime)
print(type(tradeTime))
if currentTime > tradeTime:
print("inner loop reached")
What I tried:
currentTime = datetime.strptime('%H:%M:%S')
Gives :
AttributeError: module 'datetime' has no attribute 'strptime'
currentTime = strptime('%H:%M:%S')
Gives :
AttributeError: module 'datetime' has no attribute 'strptime'
currentTime=datetime.datetime.now().time()
Gives :
TypeError: '>' not supported between instances of 'datetime.time' and 'str'
Upvotes: 2
Views: 9541
Reputation: 306
The problem you have is the result of attempting to use the ">" operator with operands of different types. Thus, the easiest way to solve this is to convert them both to a type that has a valid greater-than operator implementation, like using the unix timestamp to cast to a float.
if float(currentTime.total_seconds()) > float(tradeTime.total_seconds()):
print("inner loop reached")
Upvotes: 1