I am having issues converting my date in the right format.
I have a column that looks like this: 20130525, stored as an int64
.
I am trying to set it up as a date, but having issues.
I wrote a function that looks like this:
def reformat_dates(df):
df['column'] = pd.to_datetime(df['column'], format = "%Y-%m-%d")
return df
but when I execute the function, I end up with a column like this:
1970-01-01 00:00:00.020130525
Is there something wrong with my function that makes it default this way? I would like the format to be
2013-05-25
I think the column that you are converting is in UNIX timestamp format.
You should use unit='s'
.
def reformat_dates(df):
df['column'] = pd.to_datetime(df['column'], unit='s')
return df
Can this be useful?
df['column'] = pd.to_datetime(df['column'], format = "%Y%m%d").dt.strftime('%Y-%m-%d')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With