Home > Software design >  NAN for date Python
NAN for date Python

Time:09-29

I have a field that normally has a date value, and I would like to check if it's empty.

I've tried this:

np.isnan(row['date'] == True

However, this causes an error. This I used for string field. Is it different for each data type?

CodePudding user response:

Use boolean indexing, do not iterate

# set up a sample frame
df = pd.DataFrame(pd.date_range('2021-01-01', '2021-01-15'), columns=['Date'])
# change some values to null
df.iloc[::4] = np.nan

# boolean indexing to find all null values
df_null = df[df['Date'].isna()]

   Date
0   NaT
4   NaT
8   NaT
12  NaT

CodePudding user response:

NAN stands for Not A Number, which is not appropriate for dates. It seems that checking for null is a better approach.

  • Related