pandas - Convert dates to %y-%m-%d format in Python - Stack Overflow

PHOTO EMBED

Fri Aug 18 2023 12:31:10 GMT+0000 (Coordinated Universal Time)

Saved by @yfontes #python

>>> import pandas as pd
>>> 
>>> df = pd.DataFrame(['1/2/2020','12/31/2020','20-Jun-20'],columns=['Date'])
>>> df
         Date
0    1/2/2020
1  12/31/2020
2   20-Jun-20
>>> 
>>> df['Date'] = pd.to_datetime(df['Date'])
>>> df
        Date
0 2020-01-02
1 2020-12-31
2 2020-06-20
>>> 
>>> df['Date'] = pd.to_datetime(df['Date']).dt.strftime('%y-%m-%d')
>>> 
>>> df
       Date
0  20-01-02
1  20-12-31
2  20-06-20
>>> 


content_copyCOPY

https://stackoverflow.com/questions/66468661/convert-dates-to-y-m-d-format-in-python