无法将DataFrame保存到HDF5(“对象标头消息太大”)

发布于 2021-01-29 17:34:29

我在Pandas中有一个DataFrame:

In [7]: my_df
Out[7]: 
<class 'pandas.core.frame.DataFrame'>
Int64Index: 34 entries, 0 to 0
Columns: 2661 entries, airplane to zoo
dtypes: float64(2659), object(2)

当我尝试将其保存到磁盘时:

store = pd.HDFStore(p_full_h5)
store.append('my_df', my_df)

我得到:

  File "H5A.c", line 254, in H5Acreate2
    unable to create attribute
  File "H5A.c", line 503, in H5A_create
    unable to create attribute in object header
  File "H5Oattribute.c", line 347, in H5O_attr_create
    unable to create new attribute in header
  File "H5Omessage.c", line 224, in H5O_msg_append_real
    unable to create new message
  File "H5Omessage.c", line 1945, in H5O_msg_alloc
    unable to allocate space for message
  File "H5Oalloc.c", line 1142, in H5O_alloc
    object header message is too large

End of HDF5 error back trace

Can't set attribute 'non_index_axes' in node:
 /my_df(Group) u''.

为什么?

注意: 万一重要,DataFrame列名称是简单的小字符串:

In[12]: max([len(x) for x in list(my_df.columns)])
Out{12]: 47

Pandas 0.11和IPython,Python和HDF5的最新稳定版本提供了所有这些功能。

关注者
0
被浏览
173
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    对于列的所有元数据,HDF5的头限制为64kb。这包括名称,类型等。当您大约浏览2000列时,将用光空间来存储所有元数据。这是pytables的基本限制。我认为他们不会在短期内采取任何变通办法。您将不得不拆分表或选择其他存储格式。



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看