Suppose I have a Dataframe as:
df = {'date':['20170101', '20170102', '20170103', '20170104']}
I want to convert '20170101' to '2017-01-01 00:00:00'
How can I achieve it?
You could convert your date time string to datetime object. And then get whatever format you want:
from datetime import datetime
datetime.strptime("20170103", "%Y%m%d").strftime("%Y-%m-%d %H:%M:%S")
Output:
"2017-01-03 00:00:00"
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