Skip to content

pd.to_datetime() flaw mixed behavior yielding inconsistant results #27454

@go2sree

Description

@go2sree

Code Sample, a copy-pastable example if possible

import pandas as pd
str1='05-01-2019 00:37' 
date1=pd.to_datetime(str1).date()
print(date1)

# output  2019-05-01


str2='15-01-2019 00:37' 
date2=pd.to_datetime(str2).date()
print(date2)

# output   2019-01-15

Problem description

pd.to_datetime( ) is giving inconsistant out put, in the first piece of code where 01 is month and 05 is date after conversion these values have interchanged 01 as date and 05 as month.

but for similar code where the string value has 15 as date and 01 as month after conversion remained the same as expected.

I have tried .astype(‘datetime64’) and this also yielded the same wrong values as above code

image

image

image

Is this a known Issue and please provide workaround

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions