I am trying to apply a function to a new pandas
dataframe column.
The function should return something when pandas row is NaT
and something else in all other cases.
The input is a datetime64
class column.
Here's my attempt:
import numpy as np
def some_fun(x):
if np.isnat(x) == False:
return 'something'
else:
return 'something else'
df['new_col'] = np.vectorize(some_fun(df['date']))
Console Output:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
data
date
#0 NaT
#1 NaT
#2 NaT
#3 NaT
#4 2021-01-17
#5 NaT
#6 NaT
#7 NaT
#8 NaT
#9 NaT
Expected output:
date new_col
#0 NaT something else
#1 NaT something else
#2 NaT something else
#3 NaT something else
#4 2021-01-17 something
#5 NaT something else
#6 NaT something else
#7 NaT something else
#8 NaT something else
#9 NaT something else
How could I accomplish this task?