1

I have a dataframe "df" in Python where one column is the date represented in isoformat "2017-01-01T12:30:59.000000".

df['date']
Out[1]: 
0        2020-02-24T18:00:00
1        2020-02-24T18:00:00
2        2020-02-24T18:00:00

Is there a single command to replace the entire column in simple date like ?

df['date']
Out[1]: 
0        2020-02-24
1        2020-02-24
2        2020-02-24
Max
  • 11
  • 1
  • use this https://stackoverflow.com/questions/38067704/how-to-change-the-datetime-format-in-pandas – hamdi Feb 24 '21 at 16:57

1 Answers1

0

Cast your string date to actual datetime and then get only the date from .dt

import pandas as pd

df = pd.DataFrame({"date": ["2020-02-24T18:00:00","2020-02-24T18:00:00","2020-02-24T18:00:00"]})

df["date"] = pd.to_datetime(df["date"]).dt.date

Prayson W. Daniel
  • 14,191
  • 4
  • 51
  • 57