Skip to content

Error with dayfirst option and extra spaces in dates #22168

@Scheibs

Description

@Scheibs

I found a bad behaviour for the dayfirst option in to_datetime. It's seems that dayfirst= True is only applied on the first row.

import pandas as pd
df = pd.DataFrame(['2018-04-11 10:30:00','2018-04-11  10:30:00','2018-04-11  10:15:00'],columns=['date'])
df["date dayFristTrue"] = pd.to_datetime(df["date"], dayfirst=True)
df["date dayFristFalse"] = pd.to_datetime(df["date"], dayfirst=False)
print df
                   date   date dayFristTrue  date dayFristFalse
0   2018-04-11 10:30:00 2018-04-11 10:30:00 2018-04-11 10:30:00
1  2018-04-11  10:30:00 2018-11-04 10:30:00 2018-04-11 10:30:00
2  2018-04-11  10:15:00 2018-11-04 10:15:00 2018-04-11 10:15:00

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.14.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: fr LOCALE: None.None

pandas: 0.23.3
pytest: 3.3.2
pip: 9.0.1
setuptools: 38.4.0
Cython: 0.27.3
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: 0.10.7
IPython: 5.4.1
sphinx: 1.6.6
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.2
openpyxl: 2.4.10
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.2.2
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.1
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions