Skip to content

Commit 72f4ccb

Browse files
author
Vladimir Filimonov
committed
Docstring: pd.to_datetime - added output
1 parent 988397f commit 72f4ccb

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pandas/tseries/tools.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,30 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True,
226226
>>> i = pd.date_range('20000101',periods=100)
227227
>>> df = pd.DataFrame(dict(year = i.year, month = i.month, day = i.day))
228228
>>> pd.to_datetime(df.year*10000 + df.month*100 + df.day, format='%Y%m%d')
229+
0 2000-01-01
230+
1 2000-01-02
231+
...
232+
98 2000-04-08
233+
99 2000-04-09
234+
Length: 100, dtype: datetime64[ns]
229235
230236
Or from strings
231237
232238
>>> df = df.astype(str)
233239
>>> pd.to_datetime(df.day + df.month + df.year, format="%d%m%Y")
240+
0 2000-01-01
241+
1 2000-01-02
242+
...
243+
98 2000-04-08
244+
99 2000-04-09
245+
Length: 100, dtype: datetime64[ns]
234246
235247
Date that does not meet timestamp limitations:
236248
237-
>>> print pd.to_datetime('1300-01-01', format='%Y-%m-%d')
238-
>>> print pd.to_datetime('1300-01-01', format='%Y-%m-%d', coerce=True)
249+
>>> pd.to_datetime('13000101', format='%Y%m%d')
250+
datetime.datetime(1300, 1, 1, 0, 0)
251+
>>> pd.to_datetime('13000101', format='%Y%m%d', coerce=True)
252+
NaT
239253
"""
240254
from pandas import Timestamp
241255
from pandas.core.series import Series

0 commit comments

Comments
 (0)