I'm using the apply method to send data to a function from a Pandas DataFrame to a function. If the cell is blank then the object type is "NoneType" or "float" which is incompatible with the string comparisons that my function does. I'm filtering out this data using:
if isinstance(col1,str): #to make sure the data is a string.
My question is if there is a better way to do this since this goes against the concept of duck typing?
For context here is my code:
def check_cols(col1,col2):
if isinstance(col1,str):
var = col1
else:
var = col2
#the logical part of the function is here
#passing in data from two columns
dfcat['col3'] = dfcat.apply(lambda x: check_cols(x['col1'],x['col2']),axis=1)