Skip to content

Commit 64c8a05

Browse files
DOC: how to_datetime %S differs from strptime (#48376)
* doc update for #47134 * black and trailing spaces fixed * rewording_1 #48376 Co-authored-by: Marco Edward Gorelli <[email protected]> * rewording_2 #48376 Co-authored-by: Marco Edward Gorelli <[email protected]> Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent a72340a commit 64c8a05

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

pandas/core/tools/datetimes.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,19 @@ def to_datetime(
777777
#time-zone-handling>`_.
778778
779779
format : str, default None
780-
The strftime to parse time, e.g. :const:`"%d/%m/%Y"`. Note that
781-
:const:`"%f"` will parse all the way up to nanoseconds. See
780+
The strftime to parse time, e.g. :const:`"%d/%m/%Y"`. See
782781
`strftime documentation
783782
<https://docs.python.org/3/library/datetime.html
784-
#strftime-and-strptime-behavior>`_ for more information on choices.
783+
#strftime-and-strptime-behavior>`_ for more information on choices, though
784+
note the following differences:
785+
786+
- :const:`"%f"` will parse all the way
787+
up to nanoseconds;
788+
789+
- :const:`"%S"` without :const:`"%f"` will capture all the way
790+
up to nanoseconds if present as decimal places, and will also handle
791+
the case where the number of seconds is an integer.
792+
785793
exact : bool, default True
786794
Control how `format` is used:
787795
@@ -950,6 +958,21 @@ def to_datetime(
950958
DatetimeIndex(['1960-01-02', '1960-01-03', '1960-01-04'],
951959
dtype='datetime64[ns]', freq=None)
952960
961+
**Differences with strptime behavior**
962+
963+
:const:`"%f"` will parse all the way up to nanoseconds.
964+
965+
>>> pd.to_datetime('2018-10-26 12:00:00.0000000011',
966+
... format='%Y-%m-%d %H:%M:%S.%f')
967+
Timestamp('2018-10-26 12:00:00.000000001')
968+
969+
:const:`"%S"` without :const:`"%f"` will capture all the way
970+
up to nanoseconds if present as decimal places.
971+
972+
>>> pd.to_datetime('2017-03-22 15:16:45.433502912',
973+
... format='%Y-%m-%d %H:%M:%S')
974+
Timestamp('2017-03-22 15:16:45.433502912')
975+
953976
**Non-convertible date/times**
954977
955978
If a date does not meet the `timestamp limitations

0 commit comments

Comments
 (0)