I'm trying create a user defined function to check the length of dataframe columns and return certain value.
| Account Open Date | Account Close Date |
|---|---|
| 27-04-2011 | NaN |
| NaN | NaN |
| NaN | 01-01-2012 |
df['Account Close Date'] = df['Account Close Date'].astype(str)
df['Account Open Date'] = df['Account Open Date'].astype(str)
def close_date(row):
close_date = row['Account Close Date']
open_date = row['Account Open Date']
if len(close_date)>0:
return close_date
elif len(close_date) ==0 and len(open_date) >0:
return 'OPEN'
else:
return ''
df_tvm_calc_billing['Account Close Date'] = df_tvm_calc_billing.apply(close_date, axis =1)
TypeError: object of type 'float' has no len()
What would be the best way to do this?
I tried to convert the date values to str to identify instances where values are not NaN by checking the length of the str however, its not working.
Thanks in advance!