【问题标题】:HDFStore append to dataset - works for smaller subset, breaks for larger subsetHDFStore 附加到数据集 - 适用于较小的子集,适用于较大的子集
【发布时间】:2016-10-12 16:00:27
【问题描述】:

我正在将一个高维数据集 (90*80000) 加载到一个分块的 pandas 数据框中。使用 HDF5store 我想将此数据集写入 .hdf5。 我将数据集划分为一个矩阵 90*6 和另一个 90*remaining columns

我正在使用食谱中概述的方法,并尝试了我发现分散在互联网上的不同解决方案 - 无济于事。我认为问题可能是,第二个分区的标头太大(考虑到 64kb 的限制)。但是,我想我只是将矩阵,而不是整个数据帧传递给.append 命令。

这是我的代码:

i=0
reader = pd.read_csv(dataFile, delim_whitespace=True, chunksize=10, names=header, skiprows=1)
    for chunk in reader:
        # if i==0:
        #     print chunk.ix[:,6:].values
        #     store['df'] = chunk.ix[:,6:]
        #     print type(store['df'])
        #     print store['df'].shape
        # else:
        #     store.append('df', pd.DataFrame(chunk.ix[:,6:]))
        #     print store['df'].shape
        store.append('a',chunk.ix[:,6:])
        store.append('ID', chunk.ix[:,:6])         #the only command that works
        chunk.ix[:,6:].to_hdf(store, 'df', format="table", append=True)
        store.append('df', chunk.ix[:,6:].values)
        i+=1

这些是我单独尝试过的一堆选项,除了小数据子部分外,它们都不起作用。注释版本将第一个块写入数据集,但随后抱怨它只能附加到“表”。

一般错误信息:

Traceback(最近一次调用最后一次):文件“D:/OneDrive/Research/2016 Research Project/python files/rawToHdf5TutChunked.py”,第 109 行,在 store.append('a',chunk.ix[:,6:]) 文件“C:\Python27\lib\site-packages\pandas\io\pytables.py”,第 919 行,在 附加 **kwargs) 文件“C:\Python27\lib\site-packages\pandas\io\pytables.py”,第 1264 行,在 _write_to_group s.write(obj=value, append=append, complib=complib, **kwargs) 文件“C:\Python27\lib\site-packages\pandas\io\pytables.py”,第 3801 行, 在写 self.set_attrs() 文件“C:\Python27\lib\site-packages\pandas\io\pytables.py”,第 3052 行,在 设置属性 self.attrs.non_index_axes = self.non_index_axes 文件“C:\Python27\lib\site-packages\tables\attributeset.py”,第 461 行,在 setattr self._g__setattr(name, value) 文件“C:\Python27\lib\site-packages\tables\attributeset.py”,第 403 行,在 _g__setattr self._g_setattr(self._v_node, name, stvalue) 文件“tables\hdf5extension.pyx”,第 715 行,在 tables.hdf5extension.AttributeSet._g_setattr (tables\hdf5extension.c:7315) tables.exceptions.HDF5ExtError: HDF5 错误回溯

文件“J:\dev\src\hdf5_1_8_cmake\src\H5A.c”,第 259 行,在 H5Acreate2 中 无法在 H5A_create 中创建属性文件“J:\dev\src\hdf5_1_8_cmake\src\H5Aint.c”,第 275 行 无法在对象头文件“J:\dev\src\hdf5_1_8_cmake\src\H5Oattribute.c”中创建属性,第 347 行,在 H5O_attr_create 无法在头文件“J:\dev\src\hdf5_1_8_cmake\src\H5Omessage.c”第 224 行中创建新属性 H5O_msg_append_real 无法创建新消息文件“J:\dev\src\hdf5_1_8_cmake\src\H5Omessage.c”,第 1945 行,在 H5O_msg_alloc 无法为 H5O_alloc 中的消息文件“J:\dev\src\hdf5_1_8_cmake\src\H5Oalloc.c”,第 1142 行分配空间 对象头消息太大

HDF5 错误回溯结束

无法在节点中设置属性“non_index_axes”:/a(组)“”。结束 剩余打开的文件:t.hdf5...done

我不习惯使用大型数据集,因此欢迎任何输入。

【问题讨论】:

    标签: python pandas hdf5


    【解决方案1】:

    这是一种现在效果很好的解决方法。不过,我放弃了使用 HDF5Store。 基本上我正在使用 h5py 创建一个数据集并过度分配它,然后修剪空行:

    reader = pd.read_csv(datafile, delim_whitespace=True, chunksize=args.chunksize, names=header, skiprows=1)
    max_rows_est = 880000   #estimate for maximum number of rows per file
    i=0                     #counter for no of iterations through loop
    n_rows=0                #counter of no of processed rows
    
    for chunk in reader:
         big_chunk_shape = chunk.ix[:,6:].shape
         if i == 0:
             print 'creating dataset {0}'.format(j+1)
             dset2_data = f_hdf5.create_dataset('{0}'.format(j+1), (max_rows_est, big_chunk_shape[1]), maxshape=(None, big_chunk_shape[1]), dtype='<i4')
         dset2_data[i*big_chunk_shape[0]:(i+1)*big_chunk_shape[0], :] = chunk.ix[:,6:].values
         n_rows += big_chunk_shape[0]
         i+=1
    
    dset2_data.resize((n_rows, big_chunk_shape[1]))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-31
      • 2020-08-15
      • 2020-04-02
      • 1970-01-01
      • 2023-04-08
      • 2019-08-18
      • 2019-07-28
      • 1970-01-01
      相关资源
      最近更新 更多