使用存储的列名作为变量名提取 PyTables 表的最有效方法
以下代码提供了我需要的功能;但是,对于包含 200 个变量、64000 行的表来说,需要 10 秒多一点的时间。是否有更有效的方法来创建与列名称匹配的变量命名空间?
strExec = "a = table[:]"
for colobj in table.description._f_walk(type="Col"):
colName = colobj._v_pathname
strExec = strExec + '\n' + colName + " = a['" + colName + "']"
exec(strExec)
该代码将在分析环境中执行,并占最终用户等待时间的很大一部分;因此,我想确认这是根据 PyTable 列名称动态建立命名空间的最佳方法。
The following code provides my needed functionality; but, takes a bit more than 10 seconds for a table that includes 200 variables with 64000 rows. Is there a more efficient way to create a variable namespace that matches the column names?
strExec = "a = table[:]"
for colobj in table.description._f_walk(type="Col"):
colName = colobj._v_pathname
strExec = strExec + '\n' + colName + " = a['" + colName + "']"
exec(strExec)
The code will be executed within an analysis environment and represents a large proportion of the wait time for the end user; so, I would like confirmation that this is the best way to achieve the establishment of a namespace dynamically based upon the PyTable column names.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据unutbu的建议,表复制a=table[:]是时间消耗者。建议的代码确实提供了对没有前缀的表名变量的访问。众所周知,使用这种简化变量命名空间的方法是有问题的,因为它可能不适合不言而喻的代码。
As suggested by unutbu, the table copy a=table[:] is the time consumer. The code suggested does otherwise provide access to the tablename variables without a prefix. It's acknowledged that using this method of simplifying the variable namespace is questionable as it may not lend itself to self-evident code.