I have a df with a column with date, but the outcome is different for the lines, some lines outcomes ddmmyy some lines mmddyy. The database is all equal ddmmyy.
12/20/2021 12/21/2021 12/22/2021 12/22/2021 12/27/2021 12/27/2021 12/27/2021 12/27/2021 12/27/2021 12/27/2021 12/27/2021 12/29/2021 12/31/2021 03/01/2022 03/01/2022 03/01/2022 04/01/2022 06/01/2022 06/01/2022
Today, Im changing the code for each format, inverting mm with dd.
DezDu = pd.to_datetime((envios.loc[i, "10du"])).strftime('%m/%d/%Y')
how can I solve this problem?
CodePudding user response:
See if this works
envios['10du'] = pd.to_datetime(envios.10du)
envios['10du'] = envios['10du'].dt.strftime('%d%m%Y')
CodePudding user response:
you can simply change the format of the entire column to dd-mm-yy format
import datetime as dt
import pandas as pd
df = pd.DataFrame({'DOB': {0: '26/1/2016', 1: '1/26/2015'}})
df['DOB_1'] = pd.to_datetime(df.DOB).dt.strftime('%d/%m/%Y')
df
DOB DOB_1
0 26/1/2016 26/01/2016
1 1/26/2015 26/01/2015