JamesHudson81
JamesHudson81

Reputation: 2273

Struggle with string formatting pandas date

I have the following stringy : 2017-12-03

I am looking forward to turn the str into to_datetime, add a BDay and change the format of such date.

what i tried was :

import datetime as dt
from pandas.tseries.offsets import BDay

valor_nuevo=(pd.to_datetime(stringy,'%Y-%m-%d') + BDay(1)).strftime('%d/%m/%Y')

And outputs as error an AssertionError

Upvotes: 1

Views: 142

Answers (1)

jezrael
jezrael

Reputation: 863611

You need define parameter format or omit it in to_datetime:

valor_nuevo = (pd.to_datetime(stringy,format='%Y-%m-%d') + BDay(1)).strftime('%d/%m/%Y')

valor_nuevo = (pd.to_datetime(stringy) + BDay(1)).strftime('%d/%m/%Y')

print (valor_nuevo)
04/12/2017

Upvotes: 1

Related Questions