@@ -563,7 +563,7 @@ writing to a file). For example:
563
563
564
564
Date Parsing Functions
565
565
~~~~~~~~~~~~~~~~~~~~~~
566
- Finally, the parser allows you can specify a custom ``date_parser `` function to
566
+ Finally, the parser allows you to specify a custom ``date_parser `` function to
567
567
take full advantage of the flexibility of the date parsing API:
568
568
569
569
.. ipython :: python
@@ -573,6 +573,31 @@ take full advantage of the flexibility of the date parsing API:
573
573
date_parser = conv.parse_date_time)
574
574
df
575
575
576
+ Pandas will try to call the ``date_parser `` function in three different ways. If
577
+ an exception is raised, the next one is tried:
578
+
579
+ 1. ``date_parser `` is first called with one or more arrays as arguments,
580
+ as defined using `parse_dates ` (e.g., ``date_parser(['2013', '2013'], ['1', '2']) ``)
581
+
582
+ 2. If #1 fails, ``date_parser `` is called with all the columns
583
+ concatenated row-wise into a single array (e.g., ``date_parser(['2013 1', '2013 2']) ``)
584
+
585
+ 3. If #2 fails, ``date_parser `` is called once for every row with one or more
586
+ string arguments from the columns indicated with `parse_dates `
587
+ (e.g., ``date_parser('2013', '1') `` for the first row, ``date_parser('2013', '2') ``
588
+ for the second, etc.)
589
+
590
+ Note that performance-wise, you should try these methods of parsing dates in order:
591
+
592
+ 1. Try to infer the format using ``infer_datetime_format=True `` (see section below)
593
+
594
+ 2. If you know the format, use ``pd.to_datetime() ``:
595
+ ``date_parser=lambda x: pd.to_datetime(x, format=...) ``
596
+
597
+ 3. If you have a really non-standard format, use a custom ``date_parser `` function.
598
+ For optimal performance, this should be vectorized, i.e., it should accept arrays
599
+ as arguments.
600
+
576
601
You can explore the date parsing functionality in ``date_converters.py `` and
577
602
add your own. We would love to turn this module into a community supported set
578
603
of date/time parsers. To get you started, ``date_converters.py `` contains
0 commit comments