I have a series within a DataFrame that I read in initially as an object, and then need to convert it to a date in the form of yyyy-mm-dd where dd is the end of the month.
As an example, I have DataFrame df
with a column Date
as an object:
... Date ...
... 200104 ...
... 200508 ...
What I want when this is all said and done is a date object:
... Date ...
... 2001-04-30 ...
... 2005-08-31 ...
such that df['Date'].item()
returns
datetime.date(2001, 04, 30)
I've used the following code to get almost there, but all my dates are at the beginning of the month, not the end. Please advise.
df['Date'] = pd.to_datetime(df['Date'], format="%Y%m").dt.date
Note: I've already imported Pandas (pd), and datetime (dt)