Dataframe does not recognize month and day order

Viewed 28

I have a Excel file like this:

enter image description here

The format date is MM/DD/YYYY. Although when I try to read it with pandas, it changes the date format and gets weird:

df = pd.read_excel("test.xlsx")
df
Out[21]: 
   ID                 Date
0   1  2022-07-08 00:00:00
1   2           04/18/2022

If I try to change the format with to_datetime, the month and day for the first sample invert and it is not the same as excel file:

data['Date'] = pd.to_datetime(data["Date"]).dt.strftime('%m-%d-%Y')
   ID        Date
0   1  07-08-2022
1   2  04-18-2022

How could I see these dates in my dataframe with the excel format (MM/DD/YYYY)?

Thanks!

0 Answers
Related