【发布时间】:2021-12-08 09:31:55
【问题描述】:
我想将我的数据框存储在 h5 文件中。我的数据框是:
dfbhbh=pd.DataFrame([m1bhbh,m2bhbh,adcobhbh,edcobhbh,alisabhbh,elisabhbh,tevolbhbh,distbhbh,metalbhbh,compbhbh,weightbhbh]).T
dfbhbh.columns=['m_1','m_2','a_DCO','e_DCO','a_LISA','e_LISA','t_evol','dist','Z','component','weight']
我正在尝试使用以下方法进行转换:
hf=h5py.File('anew', 'w')
for i in range(len(dfbhbh)):
hf.create_dataset('simulations',list(dfbhbh.iloc[i]))
我得到了错误
TypeError: Can't convert element 9 (low_alpha_disc) to hsize_t
我删除了组件的整个数组(尽管它非常重要)但代码没有运行。
我也试过像这样直接在h5文件中插入数据
hf.create_dataset('simulations', m1bhbh)
我收到了这个错误
Dimensionality is too large (dimensionality is too large)
变量'm1bhbh'是一个浮点类型,长度为1499。
【问题讨论】:
-
欢迎来到 SO!请提供您的样本 df。你可以这样做:发布以下
dfbhbh.head(10).to_dict()的结果。
标签: python-3.x pandas dataframe h5py