TypeError: '>=' Not Supported Between Instances Of 'float' And 'str'
Looking to map highest matching row values from Dataframe2 to Dataframe1 using conditions. We also need to check df1['sal_date'] between df2['from'] and df['to']. df1 score id_nu
Solution 1:
I believe the problem is that you need to convert the dates into UNIX, because Python just doesn not know how to compare dates. So, try to convert the date into a datetime.datetime object, and then into UNIX time:
import datetime
import time
# Let's say, the date is:
date_string = '2019-12-22'
# We need to turn it into a list first:
date_tuple = date_string.split('-')
# Make an Datetime object
datetime_object = datetime.datetime(int(date_tuple[0]), int(date_tuple[1]), int(date_tuple[2]))
# Then, convert it into UNIX timestamp:
unix = time.mktime(datetime_object.timetuple())
print(unix)
Then, you just need to compare it like you would normally.
EDIT
I just need to check for if and else condition when there is any NaN value in df1["sal_Date"]
You can check if a variable has content or not using this:
var1 = 'hello'
var2 = ''
if var1:
print('var1 has content')
else:
print('var1 is empty')
if var2:
print('var2 has content')
else:
print('var2 is empty')
To check if there is any NaN value in a list:
foods = ['Pizza', '', 'Apple']
for food in foods:
if not food:
print('There IS an empty element in the list.')
Post a Comment for "TypeError: '>=' Not Supported Between Instances Of 'float' And 'str'"