Skip to content

Commit

Permalink
DOC: to_datetime format argument examples (#17412)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphanemann authored and jorisvandenbossche committed Sep 18, 2017
1 parent 9cc3333 commit 37e23d0
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions doc/source/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,8 @@ you can pass the ``dayfirst`` flag:
can't be parsed with the day being first it will be parsed as if
``dayfirst`` were False.

.. note::
Specifying a ``format`` argument will potentially speed up the conversion
considerably and explicitly specifying
a format string of '%Y%m%d' takes a faster path still.

If you pass a single string to ``to_datetime``, it returns single ``Timestamp``.

Also, ``Timestamp`` can accept the string input.
Note that ``Timestamp`` doesn't accept string parsing option like ``dayfirst``
or ``format``, use ``to_datetime`` if these are required.
Expand All @@ -191,6 +187,25 @@ or ``format``, use ``to_datetime`` if these are required.
pd.Timestamp('2010/11/12')
Providing a Format Argument
~~~~~~~~~~~~~~~~~~~~~~~~~~~

In addition to the required datetime string, a ``format`` argument can be passed to ensure specific parsing.
It will potentially speed up the conversion considerably.

For example:

.. ipython:: python
pd.to_datetime('2010/11/12', format='%Y/%m/%d')
pd.to_datetime('12-11-2010 00:00', format='%d-%m-%Y %H:%M')
For more information on how to specify the ``format`` options, see https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior.

Assembling datetime from multiple DataFrame columns
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 0.18.1

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

0 comments on commit 37e23d0

Please sign in to comment.