通过字符串选择列 - Pytables

时间:2014-09-08 14:31:35

标签: python pytables

我知道我们可以使用table.cols.somecolumn访问列,但我需要在我的表的10-15列上应用相同的操作。所以我想要一个迭代的解决方案。我在列表中将列的名称作为字符串:['col1','col2','col3']

所以我正在寻找以下内容:

for col in columnlist:
    thiscol = table.cols[col]
    #apply whatever operation

1 个答案:

答案 0 :(得分:0)

试试这个:

columnlist = ['col1','col2','col3']
for col in columnlist:
    thiscol = getattr(table.cols, col)
相关问题