Skip to content

Commit 3afb09d

Browse files
committed
DOC: cookbook.rst entry
1 parent 4b17314 commit 3afb09d

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

doc/source/cookbook.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,41 @@ using that handle to read.
413413
`Write a multi-row index CSV without writing duplicates
414414
<http://stackoverflow.com/questions/17349574/pandas-write-multiindex-rows-with-to-csv>`__
415415

416+
Parsing date components in multi-columns is faster with a format
417+
418+
.. code-block:: python
419+
420+
In [30]: i = pd.date_range('20000101',periods=10000)
421+
422+
In [31]: df = pd.DataFrame(dict(year = i.year, month = i.month, day = i.day))
423+
424+
In [32]: df.head()
425+
Out[32]:
426+
day month year
427+
0 1 1 2000
428+
1 2 1 2000
429+
2 3 1 2000
430+
3 4 1 2000
431+
4 5 1 2000
432+
433+
In [33]: %timeit pd.to_datetime(df.year*10000+df.month*100+df.day,format='%Y%m%d')
434+
100 loops, best of 3: 7.08 ms per loop
435+
436+
# simulate combinging into a string, then parsing
437+
In [34]: ds = df.apply(lambda x: "%04d%02d%02d" % (x['year'],x['month'],x['day']),axis=1)
438+
439+
In [35]: ds.head()
440+
Out[35]:
441+
0 20000101
442+
1 20000102
443+
2 20000103
444+
3 20000104
445+
4 20000105
446+
dtype: object
447+
448+
In [36]: %timeit pd.to_datetime(ds)
449+
1 loops, best of 3: 488 ms per loop
450+
416451
.. _cookbook.sql:
417452

418453
SQL

doc/source/io.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,7 +3171,7 @@ The key functions are:
31713171

31723172
.. autosummary::
31733173
:toctree: generated/
3174-
3174+
31753175
read_sql_table
31763176
read_sql_query
31773177
read_sql
@@ -3183,7 +3183,7 @@ The key functions are:
31833183
:func:`~pandas.read_sql_table` and :func:`~pandas.read_sql_query` (and for
31843184
backward compatibility) and will delegate to specific function depending on
31853185
the provided input (database table name or sql query).
3186-
3186+
31873187
In the following example, we use the `SQlite <http://www.sqlite.org/>`__ SQL database
31883188
engine. You can use a temporary SQLite database where data are stored in
31893189
"memory".

0 commit comments

Comments
 (0)