Home > Software design >  Convert Date to pandas from ISO 8601 format
Convert Date to pandas from ISO 8601 format

Time:10-03

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

CodePudding user response:

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)
  • Related