How to convert string to date in pandas dataframe using Python



Hi everyone,
I would like to convert strings of the form “jan.3,2017” to “2017-01-03” in a pandas dataframe column using Python.
I am able to convert this successfully with only one value,

For instance-The code goes like this:

from dateutil.parser import parse

output: “2017-01-03”

Now, i want to get the same form of output for a dataframe column. Suppose we display the starting 5 elements in the column:

0 "jan.3,2017"
1 "feb.4,2016"
2 "mar.2,2017"
3 "apr.3,2015"
4 “apr.3,2016”

I want its solution using Python only.


I tried below and it worked.
import pandas as pd
s=pd.Series([“Jan.3,2017”, “feb.4,2016”, “mar.2,2017”, “apr.3,2015” , “apr.3,2016”])
print (pd.to_datetime(s, format=’%b.%d,%Y’))

Incase of dataframe,

s=pd.Series([“Jan.3,2017”, “feb.4,2016”, “mar.2,2017”, “apr.3,2015” , “apr.3,2016”])
sf=pd.DataFrame(s, columns =[‘date_col’])
print (pd.to_datetime(sf.date_col, format=’%b.%d,%Y’)