无法使用熊猫从hdf5文件读取数据:AssertionError:无法解释[void64]的dtype

时间:2018-09-21 10:07:44

标签: python pandas hdf5 h5py pytables

我正在像这样使用熊猫读取HDF5文件:

>>> import pandas as pd
>>> store = pd.HDFStore("test.h5")
>>> store.keys()                                                          
Out[21]: ['/log', '/marker', '/signals']
>>> store['/log']
[…] # ← Long stack trace so omitted.
AssertionError: cannot interpret dtype of [void64] in [name->time,cname->time,dtype->void64,kind->None,shape->(694,)]

使用hd5dump,数据如下所示:

   DATASET "log" {
      DATATYPE  H5T_COMPOUND {
         H5T_COMPOUND {
            H5T_STD_U32LE "sec";
            H5T_STD_U32LE "usec";
         } "time";
         H5T_IEEE_F32LE "0";
         H5T_IEEE_F32LE "1";
         H5T_IEEE_F32LE "2";
         H5T_IEEE_F32LE "3";
         H5T_IEEE_F32LE "4";
         H5T_IEEE_F32LE "5";
         H5T_IEEE_F32LE "6";
         H5T_IEEE_F32LE "7";
         H5T_IEEE_F32LE "8";
         H5T_IEEE_F32LE "9";
         H5T_IEEE_F32LE "10";
         H5T_IEEE_F32LE "11";
         H5T_IEEE_F32LE "12";
         H5T_IEEE_F32LE "13";
         H5T_IEEE_F32LE "14";
         H5T_IEEE_F32LE "15";
         H5T_IEEE_F32LE "16";
         H5T_IEEE_F32LE "17";
         H5T_IEEE_F32LE "18";
         H5T_IEEE_F32LE "19";
         H5T_IEEE_F32LE "20";
         H5T_IEEE_F32LE "21";
         H5T_IEEE_F32LE "22";
         H5T_IEEE_F32LE "23";
         H5T_IEEE_F32LE "24";
         H5T_IEEE_F32LE "25";
         H5T_IEEE_F32LE "26";
      }
      DATASPACE  SIMPLE { ( 694 ) / ( H5S_UNLIMITED ) }
      DATA {
      (0): {
            {
               1537445457,
               406865
            },
            0.628541,
            13.7603,
            0.0892521,
            6.85161,
            3.55246,
            15.5923,
            2.75583,
            6.29013,
            68.0996,
            2.83735,
            14.2486,
            1.27887,
            5.79674,
            67.9511,
            3.04454,
            15.4438,
            0.433652,
            6.47199,
            0.440571,
            nan,
            nan,
            nan,
            0,
            0,
            0,
            0,
            0
         },
         […]

我试图找出AssertionError是由于名称(数字而不是有用的东西)还是NaN值引起的。

我正在查看列的pytables选择,但文档无济于事,并且错误消息难以理解。例如:

>>> store.select('/log', where="column=0")
[…]

ValueError: The passed where expression: column=0                              
            contains an invalid variable reference                             
            all of the variable references must be a reference to              
            an axis (e.g. 'index' or 'columns'), or a data_column              
            The currently defined references are: 24,index,26,20,21,22,23,1,0,3,2,5,4,7,6,9,8,25,11,10,13,12,15,14,17,16,19,18,time 

使用h5py,我得到:

>>> import h5py
>>> f = h5py.File('test.h5', 'r')
>>> f.keys()                                                              
[u'log', u'marker', u'signals']
>>> f['/log']                                                             
<HDF5 dataset "log": shape (694,), type "|V116">
>>> f['/log'][0]                                                          
((1537445457, 406865), 0.62854123, 13.760307, 0.0892521, 6.851607, 3.5524576, 15.592277, 2.755828, 6.290126, 68.09964, 2.8373492, 14.248627, 1.2788678, 5.7967386, 67.9511, 3.0445364, 15.443768, 0.43365178, 6.4719925, 0.4405711, nan, nan, nan, 0., 0., 0., 0., 0.)

我在做什么错了?

0 个答案:

没有答案