Astropy:以列名中的特定模式遍历表中的列

问题描述 投票:0回答:1

我有一个令人讨厌的表t,因此t.colnames显示如下内容:

['a', 'b', 'c', 'err_a', 'err_b', 'err_c', 'd', 'e', 'f']

我想为表中的每一行确定名称中具有'err'的列的最大值。

我可以做类似的事情

for line in t:
    max = 0
    for col in t.colnames:
        if col[:3] == 'err':
            if line[col] > max:
                max = line[col]
    print(max)

是否有更简单的方法?

max astropy
1个回答
0
投票

假设您想要所有“ err”列中的最大值,您可以这样做:

max(t[c].max() for c in t.colnames if 'err' in c)
© www.soinside.com 2019 - 2024. All rights reserved.