'Change the format of the date to the YYYY-DD-MM in pandas dataframe [duplicate]

I have a dataframe as follow:

import pandas as pd
import numpy as np
df = pd.DataFrame()
df['c0'] = [ '2019-01-01 06:00:00',  '2019-01-03 06:00:00', '2019-05-03 06:00:00' ]
df['c1'] = [ 0.4452, 0.2064, 0.1416]

I want to change the format of the date as "yyyy-dd-mm". The final dataframe which I want is:

enter image description here



Solution 1:[1]

You can convert it to datetime type and use the strftime() method to change the date format.

df['c0'] = pd.to_datetime(df['c0']).dt.strftime('%Y-%d-%m')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1