File tree 2 files changed +37
-2
lines changed
2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -413,6 +413,41 @@ using that handle to read.
413
413
`Write a multi-row index CSV without writing duplicates
414
414
<http://stackoverflow.com/questions/17349574/pandas-write-multiindex-rows-with-to-csv> `__
415
415
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
+
416
451
.. _cookbook.sql :
417
452
418
453
SQL
Original file line number Diff line number Diff line change @@ -3171,7 +3171,7 @@ The key functions are:
3171
3171
3172
3172
.. autosummary ::
3173
3173
:toctree: generated/
3174
-
3174
+
3175
3175
read_sql_table
3176
3176
read_sql_query
3177
3177
read_sql
@@ -3183,7 +3183,7 @@ The key functions are:
3183
3183
:func: `~pandas.read_sql_table ` and :func: `~pandas.read_sql_query ` (and for
3184
3184
backward compatibility) and will delegate to specific function depending on
3185
3185
the provided input (database table name or sql query).
3186
-
3186
+
3187
3187
In the following example, we use the `SQlite <http://www.sqlite.org/ >`__ SQL database
3188
3188
engine. You can use a temporary SQLite database where data are stored in
3189
3189
"memory".
You can’t perform that action at this time.
0 commit comments