I have a dataframe with the dates column listed in the following format 2017/08/23
and I would like to convert all values in the column to the following format:
2011-09-13
00:00:00
What is the best way to do this?
Use pd.to_datetime
from Pandas:
import pandas as pd
from io import StringIO
date_string = StringIO("""date
2017/08/23
2017/08/24
2017/08/25""")
df = pd.read_csv(date_string)
pd.to_datetime(df['date'])
Output:
0 2017-08-23
1 2017-08-24
2 2017-08-25
Name: date, dtype: datetime64[ns]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments