ISO Date Conversion
Tags: #pandas #python #date #conversion #isoformat #dateconversion
This notebook will help you understand how to convert any date to ISO date format.

Input

Import Libraries

1
import pandas as pd
2
from dateutil.parser import parse
Copied!

Create Sample Dataframe

1
dict1 = {
2
"Name": ["Peter","Dolly","Maggie","David","Isabelle"],
3
"Date":["20/2/2021","19/8/2014","8/9/2000","4/3/2013","14/7/1995"],
4
"Second Date":["August 20,2011","September 16,1993","January 23,2009","October 17,2019","March 4,2021"]
5
}
Copied!
1
data=pd.DataFrame(dict1)
Copied!
1
data
Copied!

Model

ISO date format is the standard internationally acceptable format of writing date. It eliminates the differences between the date format of different regions. This template will convert any date to ISO format. There are 2 date formats in the sample data and the conversion of both takes place below
1
# Converting the first Date into ISO Format
2
data["Date"]=pd.to_datetime(data["Date"]).dt.strftime('%Y-%m-%d')
Copied!
1
# Converting the second date into ISO Format
2
data["Second Date"]=data["Second Date"].apply(lambda i: parse(i))
Copied!

Output

Display result

1
data
Copied!
Copy link
Edit on GitHub