【发布时间】:2021-11-23 14:15:52
【问题描述】:
我正在使用 pytables,并且正在尝试实现父子关系。例如,我想存储多支球队,每支球队都有多名球员。我可以通过以下方式做到这一点:
import tables as tb
class Team(tb.IsDescription):
id = tb.Int32Col() #Id of team
name = tb.StringCol(20) #Name of team
class Player(tb.IsDescription):
team = tb.Int32Col() #Link to team::team_id
name = tb.StringCol(20) #Name of player
f = tb.open_file('test.h5',mode='w',title='test')
table_team = f.create_table(f.root,'teams',Team)
table_player = f.create_table(f.root,'players',Player)
team = table_team.row
team['id'] = 0
team['name'] = 'Barcelona'
team.append()
player0 = table_player.row
player0['team'] = 0
player0['name'] = 'De Jong'
player0.append()
player1 = table_player.row
player1['team'] = 0
player1['name'] = 'Fati'
player1.append()
f.close()
但是,pytables 文档对此做了以下说明 (https://www.pytables.org/cookbook/hints_for_sql_users.html):
"你可能已经注意到 PyTables 中的查询只覆盖一张表。 事实上,没有办法直接在两个之间执行连接 PyTables 中的表(请记住,它不是关系数据库)。”
然后它继续为连接查询提供一些解决方法。但是,正如他们所说,pytables 不是关系数据库。因此,我没有使用基于关系的方法和解决方法,而是提出以下问题:
在 pytables 中实现父子结构的推荐/标准方法是什么?
【问题讨论】:
-
你需要对他们做什么?
-
@ScottHunter 对于我目前正在处理的情况,它只是存储值并稍后绘制它们。基本上,父节点是一个实验,子节点是数据点,会定期添加。
标签: python parent-child pytables