Skip to content

Commit fd5e7c6

Browse files
author
MarcoGorelli
committed
update user guide;
1 parent 389dd71 commit fd5e7c6

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

doc/source/user_guide/io.rst

+6-27
Original file line numberDiff line numberDiff line change
@@ -908,26 +908,8 @@ data columns:
908908
Date parsing functions
909909
++++++++++++++++++++++
910910

911-
Finally, the parser allows you to specify a custom ``date_parser`` function to
912-
take full advantage of the flexibility of the date parsing API:
913-
914-
.. ipython:: python
915-
916-
df = pd.read_csv(
917-
"tmp.csv", header=None, parse_dates=date_spec, date_parser=pd.to_datetime
918-
)
919-
df
920-
921-
pandas will try to call the ``date_parser`` function in three different ways. If
922-
an exception is raised, the next one is tried:
923-
924-
1. ``date_parser`` is first called with one or more arrays as arguments,
925-
as defined using ``parse_dates`` (e.g., ``date_parser(['2013', '2013'], ['1', '2'])``).
926-
927-
2. If #1 fails, ``date_parser`` is called with all the columns
928-
concatenated row-wise into a single array (e.g., ``date_parser(['2013 1', '2013 2'])``).
929-
930-
Note that performance-wise, you should try these methods of parsing dates in order:
911+
Finally, the parser allows you to specify a custom ``date_format``.
912+
Performance-wise, you should try these methods of parsing dates in order:
931913

932914
1. If you know the format, use ``date_format``, e.g.:
933915
``date_format="%d/%m/%Y"``.
@@ -962,16 +944,13 @@ an object-dtype column with strings, even with ``parse_dates``.
962944
df = pd.read_csv(StringIO(content), parse_dates=["a"])
963945
df["a"]
964946
965-
To parse the mixed-timezone values as a datetime column, pass a partially-applied
966-
:func:`to_datetime` with ``utc=True`` as the ``date_parser``.
947+
To parse the mixed-timezone values as a datetime column, read in as ``object`` dtype and
948+
then call :func:`to_datetime` with ``utc=True``.
967949

968950
.. ipython:: python
969951
970-
df = pd.read_csv(
971-
StringIO(content),
972-
parse_dates=["a"],
973-
date_parser=lambda col: pd.to_datetime(col, utc=True),
974-
)
952+
df = pd.read_csv(StringIO(content))
953+
df["a"] = pd.to_datetime(df["a"], utc=True)
975954
df["a"]
976955
977956

0 commit comments

Comments
 (0)