0

I would like to find values in a column (clear_date) that do not correspond to a valid date. The date is formatted as '%Y/%m/%d'.

I've tried the following piece of code but, the resulting variable doesn't have any rows!

x_test = dataset[dataset['clear_date'] == "NaT"].copy()

Here is a picture for reference: enter image description here

PieCot
  • 3,564
  • 1
  • 12
  • 20

1 Answers1

0

If the clear_date column is already a proper datetime, then:

x_test = dataset.loc[dataset['clear_date'].isnull()].copy()

Otherwise, e.g. if it is a string:

x_test = dataset.loc[pd.to_date_time(dataset['clear_date']).isnull()].copy()
Pierre D
  • 24,012
  • 7
  • 60
  • 96