How can I load a data frame saved in pandas as an HDF5 file in R?

Viewed 1407

I saved a data frame in pandas in an HDF5 file:

import numpy as np
import pandas as pd
np.random.seed(1)
frame = pd.DataFrame(np.random.randn(4, 3), columns=list('bde'), 
                     index=['Utah', 'Ohio', 'Texas', 'Oregon'])
print('frame: {0}'.format(frame))
store = pd.HDFStore('file.h5')
store['df'] =  frame
store.close()

The frame looks as follows:

frame:                b         d         e
Utah              1.624345 -0.611756 -0.528172
Ohio             -1.072969  0.865408 -2.301539
Texas             1.744812 -0.761207  0.319039
Oregon           -0.249370  1.462108 -2.060141

I am trying to load it in R:

#source("http://bioconductor.org/biocLite.R")
#biocLite("rhdf5")    
library(rhdf5)
frame = h5ls("file.h5")    
frame

However, once loaded in R it looks as follows:

> frame
  group          name       otype dclass   dim
0     /            df   H5I_GROUP             
1   /df         axis0 H5I_DATASET STRING     3
2   /df         axis1 H5I_DATASET STRING     4
3   /df  block0_items H5I_DATASET STRING     3
4   /df block0_values H5I_DATASET  FLOAT 3 x 4
> 

I also tried:

frame2 = h5read("file.h5", '/df')
frame2

However it returns several values but no data frame:

> frame2
$axis0
[1] "b" "d" "e"

$axis1
[1] "Utah"   "Ohio"   "Texas"  "Oregon"

$block0_items
[1] "b" "d" "e"

$block0_values
           [,1]       [,2]       [,3]       [,4]
[1,]  1.6243454 -1.0729686  1.7448118 -0.2493704
[2,] -0.6117564  0.8654076 -0.7612069  1.4621079
[3,] -0.5281718 -2.3015387  0.3190391 -2.0601407

How can I load a data frame saved in pandas as an HDF5 file, in R?

1 Answers
Related