Skip to content

Commit 37e23d0

Browse files
philipphanemannjorisvandenbossche
authored andcommitted
DOC: to_datetime format argument examples (#17412)
1 parent 9cc3333 commit 37e23d0

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

doc/source/timeseries.rst

+20-5
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,8 @@ you can pass the ``dayfirst`` flag:
175175
can't be parsed with the day being first it will be parsed as if
176176
``dayfirst`` were False.
177177

178-
.. note::
179-
Specifying a ``format`` argument will potentially speed up the conversion
180-
considerably and explicitly specifying
181-
a format string of '%Y%m%d' takes a faster path still.
182-
183178
If you pass a single string to ``to_datetime``, it returns single ``Timestamp``.
179+
184180
Also, ``Timestamp`` can accept the string input.
185181
Note that ``Timestamp`` doesn't accept string parsing option like ``dayfirst``
186182
or ``format``, use ``to_datetime`` if these are required.
@@ -191,6 +187,25 @@ or ``format``, use ``to_datetime`` if these are required.
191187
192188
pd.Timestamp('2010/11/12')
193189
190+
Providing a Format Argument
191+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
192+
193+
In addition to the required datetime string, a ``format`` argument can be passed to ensure specific parsing.
194+
It will potentially speed up the conversion considerably.
195+
196+
For example:
197+
198+
.. ipython:: python
199+
200+
pd.to_datetime('2010/11/12', format='%Y/%m/%d')
201+
202+
pd.to_datetime('12-11-2010 00:00', format='%d-%m-%Y %H:%M')
203+
204+
For more information on how to specify the ``format`` options, see https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior.
205+
206+
Assembling datetime from multiple DataFrame columns
207+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208+
194209
.. versionadded:: 0.18.1
195210

196211
You can also pass a ``DataFrame`` of integer or string columns to assemble into a ``Series`` of ``Timestamps``.

0 commit comments

Comments
 (0)