Skip to content

Commit 20dace8

Browse files
committed
Merge pull request #5887 from jseabold/to-datetime-example
DOC: Add two examples to to_datetime
2 parents 9747029 + d7f2d1d commit 20dace8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tseries/tools.py

+14
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ def to_datetime(arg, errors='ignore', dayfirst=False, utc=None, box=True,
7979
Returns
8080
-------
8181
ret : datetime if parsing succeeded
82+
83+
Examples
84+
--------
85+
Take separate series and convert to datetime
86+
87+
>>> import pandas as pd
88+
>>> i = pd.date_range('20000101',periods=100)
89+
>>> df = pd.DataFrame(dict(year = i.year, month = i.month, day = i.day))
90+
>>> pd.to_datetime(df.year*10000 + df.month*100 + df.day, format='%Y%m%d')
91+
92+
Or from strings
93+
94+
>>> df = df.astype(str)
95+
>>> pd.to_datetime(df.day + df.month + df.year, format="%d%m%Y")
8296
"""
8397
from pandas import Timestamp
8498
from pandas.core.series import Series

0 commit comments

Comments
 (0)