@@ -295,79 +295,171 @@ Updated PyTables Support
295
295
296
296
:ref: `Docs <io.hdf5 >` for PyTables ``Table `` format & several enhancements to the api. Here is a taste of what to expect.
297
297
298
- .. ipython :: python
299
- :suppress:
300
- :okexcept:
298
+ .. code-block :: ipython
301
299
302
- import os
300
+ In [41]: store = pd.HDFStore('store.h5')
303
301
304
- os.remove(' store.h5' )
302
+ In [42]: df = pd.DataFrame(np.random.randn(8, 3),
303
+ ....: index=pd.date_range('1/1/2000', periods=8),
304
+ ....: columns=['A', 'B', 'C'])
305
305
306
- .. ipython :: python
306
+ In [43]: df
307
+ Out[43]:
308
+ A B C
309
+ 2000-01-01 -2.036047 0.000830 -0.955697
310
+ 2000-01-02 -0.898872 -0.725411 0.059904
311
+ 2000-01-03 -0.449644 1.082900 -1.221265
312
+ 2000-01-04 0.361078 1.330704 0.855932
313
+ 2000-01-05 -1.216718 1.488887 0.018993
314
+ 2000-01-06 -0.877046 0.045976 0.437274
315
+ 2000-01-07 -0.567182 -0.888657 -0.556383
316
+ 2000-01-08 0.655457 1.117949 -2.782376
307
317
308
- store = pd.HDFStore(' store.h5' )
309
- df = pd.DataFrame(np.random.randn(8 , 3 ),
310
- index = pd.date_range(' 1/1/2000' , periods = 8 ),
311
- columns = [' A' , ' B' , ' C' ])
312
- df
318
+ [8 rows x 3 columns]
313
319
314
- # appending data frames
315
- df1 = df[0 :4 ]
316
- df2 = df[4 :]
317
- store.append(' df' , df1)
318
- store.append(' df' , df2)
319
- store
320
+ # appending data frames
321
+ In [44]: df1 = df[0:4]
320
322
321
- # selecting the entire store
322
- store.select(' df' )
323
+ In [45]: df2 = df[4:]
323
324
324
- .. ipython :: python
325
- :okwarning:
325
+ In [46]: store.append('df', df1)
326
326
327
- wp = pd.Panel(np.random.randn(2 , 5 , 4 ), items = [' Item1' , ' Item2' ],
328
- major_axis = pd.date_range(' 1/1/2000' , periods = 5 ),
329
- minor_axis = [' A' , ' B' , ' C' , ' D' ])
330
- wp
327
+ In [47]: store.append('df', df2)
331
328
332
- # storing a panel
333
- store.append(' wp' , wp)
329
+ In [48]: store
330
+ Out[48]:
331
+ <class 'pandas.io.pytables.HDFStore'>
332
+ File path: store.h5
333
+ /df frame_table (typ->appendable,nrows->8,ncols->3,indexers->[index])
334
334
335
- # selecting via A QUERY
336
- store.select(' wp' , " major_axis>20000102 and minor_axis=['A','B']" )
335
+ # selecting the entire store
336
+ In [49]: store.select('df')
337
+ Out[49]:
338
+ A B C
339
+ 2000-01-01 -2.036047 0.000830 -0.955697
340
+ 2000-01-02 -0.898872 -0.725411 0.059904
341
+ 2000-01-03 -0.449644 1.082900 -1.221265
342
+ 2000-01-04 0.361078 1.330704 0.855932
343
+ 2000-01-05 -1.216718 1.488887 0.018993
344
+ 2000-01-06 -0.877046 0.045976 0.437274
345
+ 2000-01-07 -0.567182 -0.888657 -0.556383
346
+ 2000-01-08 0.655457 1.117949 -2.782376
337
347
338
- # removing data from tables
339
- store.remove(' wp' , " major_axis>20000103" )
340
- store.select(' wp' )
348
+ [8 rows x 3 columns]
349
+
350
+ .. code-block :: ipython
351
+
352
+ In [50]: wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
353
+ ....: major_axis=pd.date_range('1/1/2000', periods=5),
354
+ ....: minor_axis=['A', 'B', 'C', 'D'])
355
+
356
+ In [51]: wp
357
+ Out[51]:
358
+ <class 'pandas.core.panel.Panel'>
359
+ Dimensions: 2 (items) x 5 (major_axis) x 4 (minor_axis)
360
+ Items axis: Item1 to Item2
361
+ Major_axis axis: 2000-01-01 00:00:00 to 2000-01-05 00:00:00
362
+ Minor_axis axis: A to D
363
+
364
+ # storing a panel
365
+ In [52]: store.append('wp', wp)
366
+
367
+ # selecting via A QUERY
368
+ In [53]: store.select('wp', [pd.Term('major_axis>20000102'),
369
+ ....: pd.Term('minor_axis', '=', ['A', 'B'])])
370
+ ....:
371
+ Out[53]:
372
+ <class 'pandas.core.panel.Panel'>
373
+ Dimensions: 2 (items) x 3 (major_axis) x 2 (minor_axis)
374
+ Items axis: Item1 to Item2
375
+ Major_axis axis: 2000-01-03 00:00:00 to 2000-01-05 00:00:00
376
+ Minor_axis axis: A to B
377
+
378
+ # removing data from tables
379
+ In [54]: store.remove('wp', pd.Term('major_axis>20000103'))
380
+ Out[54]: 8
381
+
382
+ In [55]: store.select('wp')
383
+ Out[55]:
384
+ <class 'pandas.core.panel.Panel'>
385
+ Dimensions: 2 (items) x 3 (major_axis) x 4 (minor_axis)
386
+ Items axis: Item1 to Item2
387
+ Major_axis axis: 2000-01-01 00:00:00 to 2000-01-03 00:00:00
388
+ Minor_axis axis: A to D
389
+
390
+ # deleting a store
391
+ In [56]: del store['df']
392
+
393
+ In [57]: store
394
+ Out[57]:
395
+ <class 'pandas.io.pytables.HDFStore'>
396
+ File path: store.h5
397
+ /wp wide_table (typ->appendable,nrows->12,ncols->2,indexers->[major_axis,minor_axis])
341
398
342
- # deleting a store
343
- del store[' df' ]
344
- store
345
399
346
400
**Enhancements **
347
401
348
402
- added ability to hierarchical keys
349
403
350
- .. ipython :: python
404
+ .. code-block :: ipython
405
+
406
+ In [58]: store.put('foo/bar/bah', df)
407
+
408
+ In [59]: store.append('food/orange', df)
351
409
352
- store.put(' foo/bar/bah' , df)
353
- store.append(' food/orange' , df)
354
- store.append(' food/apple' , df)
355
- store
410
+ In [60]: store.append('food/apple', df)
356
411
357
- # remove all nodes under this level
358
- store.remove(' food' )
359
- store
412
+ In [61]: store
413
+ Out[61]:
414
+ <class 'pandas.io.pytables.HDFStore'>
415
+ File path: store.h5
416
+ /foo/bar/bah frame (shape->[8,3])
417
+ /food/apple frame_table (typ->appendable,nrows->8,ncols->3,indexers->[index])
418
+ /food/orange frame_table (typ->appendable,nrows->8,ncols->3,indexers->[index])
419
+ /wp wide_table (typ->appendable,nrows->12,ncols->2,indexers->[major_axis,minor_axis])
420
+
421
+ # remove all nodes under this level
422
+ In [62]: store.remove('food')
423
+
424
+ In [63]: store
425
+ Out[63]:
426
+ <class 'pandas.io.pytables.HDFStore'>
427
+ File path: store.h5
428
+ /foo/bar/bah frame (shape->[8,3])
429
+ /wp wide_table (typ->appendable,nrows->12,ncols->2,indexers->[major_axis,minor_axis])
360
430
361
431
- added mixed-dtype support!
362
432
363
433
.. ipython :: python
364
434
365
- df[' string' ] = ' string'
366
- df[' int' ] = 1
367
- store.append(' df' , df)
368
- df1 = store.select(' df' )
369
- df1
370
- df1.get_dtype_counts()
435
+ In [64 ]: df[' string' ] = ' string'
436
+
437
+ In [65 ]: df[' int' ] = 1
438
+
439
+ In [66 ]: store.append(' df' , df)
440
+
441
+ In [67 ]: df1 = store.select(' df' )
442
+
443
+ In [68 ]: df1
444
+ Out[68 ]:
445
+ A B C string int
446
+ 2000 - 01 - 01 - 2.036047 0.000830 - 0.955697 string 1
447
+ 2000 - 01 - 02 - 0.898872 - 0.725411 0.059904 string 1
448
+ 2000 - 01 - 03 - 0.449644 1.082900 - 1.221265 string 1
449
+ 2000 - 01 - 04 0.361078 1.330704 0.855932 string 1
450
+ 2000 - 01 - 05 - 1.216718 1.488887 0.018993 string 1
451
+ 2000 - 01 - 06 - 0.877046 0.045976 0.437274 string 1
452
+ 2000 - 01 - 07 - 0.567182 - 0.888657 - 0.556383 string 1
453
+ 2000 - 01 - 08 0.655457 1.117949 - 2.782376 string 1
454
+
455
+ [8 rows x 5 columns]
456
+
457
+ In [69 ]: df1.get_dtype_counts()
458
+ Out[69 ]:
459
+ float64 3
460
+ int64 1
461
+ object 1
462
+ dtype: int64
371
463
372
464
- performance improvements on table writing
373
465
- support for arbitrarily indexed dimensions
@@ -392,13 +484,6 @@ Updated PyTables Support
392
484
- minor change to select and remove: require a table ONLY if where is also
393
485
provided (and not None)
394
486
395
- .. ipython :: python
396
- :suppress:
397
-
398
- store.close()
399
- import os
400
- os.remove(' store.h5' )
401
-
402
487
**Compatibility **
403
488
404
489
0.10 of ``HDFStore `` is backwards compatible for reading tables created in a prior version of pandas,
0 commit comments