python - Pandas replace months names within dataframe values -


i have dataset months 'january', 'february' etc. example '23:12 25 april 2016'

the goal transform '23:12 25 4 2016' using .replace() whole dataframe.

any ideas? thanks.

udp. forgot main problem: example has months in english, have them in other language need unicode replacement first to_datetime

iiuc can use to_datetime reformating dates in column date:

print df                   date 0  23:12 25 april 2016  df['date'] = pd.to_datetime(df['date']) print df                   date 0 2016-04-25 23:12:00 

another solution add parameter format:

df['date'] = pd.to_datetime(df['date'], format="%h:%m %d %b %y") print df                  date 0 2016-04-25 23:12:00 

if names of months russian use replace:

import pandas pd  df = pd.dataframe({'date': [u'23:12 25 январь 2016']})  d = {u'январь':'january', u'февраль':'february', u'март':'march'}  df['date'] = df['date'].replace(d, regex=true)  df['date'] = pd.to_datetime(df['date'], format="%h:%m %d %b %y") print df                  date 0 2016-01-25 23:12:00 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -