【问题标题】:Convert panda dataframe to h5 file将熊猫数据框转换为 h5 文件
【发布时间】: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


【解决方案1】:

试试:

hf.create_dataset('simulations', data = m1bhbh)

而不是

hf.create_dataset('simulations', m1bhbh)

(不要忘记在运行之前清除输出。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2021-08-21
    • 1970-01-01
    相关资源
    最近更新 更多