Skip to content

Commit 389a9d9

Browse files
committed
example for to_datetime api
1 parent 7d9b27d commit 389a9d9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/core/tools/datetimes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
250250
>>> %timeit pd.to_datetime(s,infer_datetime_format=False)
251251
1 loop, best of 3: 471 ms per loop
252252
253+
Passing require_iso8601=True will only parse ISO8601-compliant datetime
254+
strings and treat others as non-parseable dates.
255+
256+
>>> s = pd.Series(['M1809', 'M1701', pd.Timestamp('20130101')])
257+
258+
>>> pd.to_datetime(s, require_iso8601=False, errors='raise')
259+
0 1809-01-01
260+
1 1701-01-01
261+
2 2013-01-01
262+
dtype: datetime64[ns]
263+
264+
>>> pd.to_datetime(s, require_iso8601=True, errors='coerce')
265+
0 NaT
266+
1 NaT
267+
2 2013-01-01
268+
dtype: datetime64[ns]
269+
253270
Using a unix epoch time
254271
255272
>>> pd.to_datetime(1490195805, unit='s')

0 commit comments

Comments
 (0)