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
Post a Comment