Convert Date to pandas from ISO 8601 format

Question:

I have a date it look like this

2021-12-14T20:32:34Z

how can i convert it to someting like this

2021-12-14 20:32
Asked By: IvonaK

||

Answers:

If you want to do this using Pandas, you can use pandas to convert iso date to datetime object then strftime to convert timestamp into string format

import pandas as pd
import datetime

iso_date = '2021-12-14T20:32:34Z'
fmt = '%Y-%m-%d %H:%M'
pd.to_datetime(iso_date).strftime(fmt)

to apply it to a series of dates of DataFrame column you can replace iso_date with the series of dates and use this code

pd.to_datetime(iso_date).dt.strftime(fmt)
Answered By: Farid
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.