【问题标题】:View columns within a HDF5 table查看 HDF5 表中的列
【发布时间】:2019-05-20 18:14:31
【问题描述】:

目前我可以查看 HDF5 存储中的每个表以及该表中的数据。

with pd.HDFStore(left_file, 'r') as hdf:
   tables = hdf.keys()
   for table in tables:
       print(hdf.select('{0}'.format(table))

但是我怎样才能得到每个表中的列的列表呢?

【问题讨论】:

  • 到目前为止您尝试了哪些方法,为什么不能生成您想要的格式?
  • base_items 据我所知是一个元组。所以我试过 print(" ", tab[0]) 会告诉我表名,但是 print(" ", tab[2]) 给了我一个超出范围的索引错误。我已经在上面更新了

标签: python pandas hdf5


【解决方案1】:

多亏了这些视频,我才能够提高我对熊猫的了解。 https://www.youtube.com/user/DrNoureddinSadawi/videos

这是我的解决方案。它列出了表格及其列标题。

with pd.HDFStore(hdfs_file, 'r') as hdf:
    tables = hdf.keys()
    for table in tables:
        print(table)
        table_data = hdf.get(table)
        column_list = table_data.columns.values
        for column in column_list:
            print(" - {0}".format(column))

【讨论】:

    猜你喜欢
    • 2012-08-01
    • 2014-12-15
    • 2014-09-19
    • 2018-10-11
    • 2012-02-12
    • 1970-01-01
    • 2015-11-07
    • 2016-12-08
    • 2021-10-01
    相关资源
    最近更新 更多