Parse Month Day ('%b %d') Date Column Into Datetime Using Current Year
I have a column in the following format Date June 22 June 23 June 24 June 25 I am trying to convert this column to datetime within a pandas df with the format YYYY-mm-dd How can I
Solution 1:
Try:
>>> pd.to_datetime(df['Date'].add(' 2021'), format="%B %d %Y")
02021-06-2212021-06-2322021-06-2432021-06-25
Name: Date, dtype: datetime64[ns]
Suggested by @HenryEcker, to add the current year instead of specifying 2021
:
pd.to_datetime(df['Date'].add(f' {pd.Timestamp.now().year}'), format="%B %d %Y")
Post a Comment for "Parse Month Day ('%b %d') Date Column Into Datetime Using Current Year"