How can I work with different date formats in the same column at the same time?

This is question is related to screen 5 of “Working with Dates and Times in Python”.
I am trying to work on the original dataset for White House Visitor Archive - 2015 rather than the one that the mission is using. I have extracted the data and pulled out the columns similar to the data set in the mission. Below is the link to the dataset. I am using the 2015 dataset.

https://obamawhitehouse.archives.gov/briefing-room/disclosures/visitor-records

While converting the appt_start_date column, I was getting error and traced that some of the columns were not having time stamp and there are multiple time formats in the same column. Below is the code that I originally used

Traceback Error:

Is there a way to resolve this and update multiple date-time formats in the same column?

Also, I wrote the below code and it worked fine for now since there were just two different formats. Is there a better way to do perform this task? Any help would be appreciated?

Thanks in advance!

Hello @itika.sharma10, Welcome to the DataQuest Community!!

In your first code you code a ValueError since the format that you provided did not match the date format. As you can see:

ValueError: time data '10/19/2014' does not match format '%m/%d/%Y %H:%M'

The date format is in '%m/%d/%Y' thats why your second code works.

@info.victoromondi - yes, I got that part but that was after I came across the error method. Is there any better way to work with multiple date formats at one go.

yes, it depends on how the date is formatted. Alwys check the format first.