2

My data frame consists of a column of dates, which are not necessarily in the correct format. for example: 13/13/2020 or 13/10/2011 - if the format is mm/dd/yyyy.

1 Answer 1

2

I recommend you use the built in functionality for something like this:

pd.to_datetime(Q4_df['issdt'], infer_datetime_format=True, errors='coerce')

Tune the errors param to get the behavior you want:

errors{‘ignore’, ‘raise’, ‘coerce’}, default ‘raise’
   If ‘raise’, then invalid parsing will raise an exception.
   If ‘coerce’, then invalid parsing will be set as NaT.
   If ‘ignore’, then invalid parsing will return the input.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.