Issue
I have encountered this problem, and I would like to understand why Pandas changes the month and day in places.
The data is shown at the top as it looks before formatting in DateTime, and at the bottom, respectively, after formatting.
can you explain to me why this is happening or how to fix it?
Thank you all in advance for the answer!
P.S I tried to format the data without "strftime" still swaps the day and month
Solution
08.09.2016
is an ambiguous format (depending on the locale, it is interpreted as Aug 9 or Sep 8). By default, Pandas parses this as %m.%d.%Y
. To force parsing as %d.%m.%Y
, use dayfirst=True
.
In [6]: pd.to_datetime('08.09.2016').strftime('%d.%m.%Y')
Out[6]: '09.08.2016'
In [7]: pd.to_datetime('08.09.2016', dayfirst=True).strftime('%d.%m.%Y')
Out[7]: '08.09.2016'
Note that 21.09.2018
is unambiguous, since 21
cannot be a month.
Answered By - Igor Raush
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.