0

my date time format in excel is 01-12-2010 08:26 (date =01,month =12) when i import that into pandas and change dtype to datetime, month and date both get swapped.I am new to this please help

Output of pandas is 
 x .date 
 12
 x. month
 1

Excel
Invoice date = 01/12/2010 08:26 PANDAS When import using sales = pd.read_csv() sales["InvoiceDate"] = sales["InvoiceDate"].astype("datetime64[ns]")

[ln] y["InvoiceDate"].loc[0].
[Out] Timestamp['2010-01-12 08:26:00']

[ln] y["InvoiceDate"].loc[0].day 
[out] 12

the output of this should be 1 instead of 12 where i am getting it wrong please help

Dev Khadka
  • 5,142
  • 4
  • 19
  • 33
  • Possible duplicate of [Python Pandas : pandas.to\_datetime() is switching day & month when day is less than 13](https://stackoverflow.com/questions/50367656/python-pandas-pandas-to-datetime-is-switching-day-month-when-day-is-less-t) – Erfan Oct 14 '19 at 09:30

1 Answers1

0

you can use pd.to_datetime with parameter dayfirst like below

pd.to_datetime("01/12/2010 08:26", dayfirst=True)
Dev Khadka
  • 5,142
  • 4
  • 19
  • 33