我有一个令人讨厌的表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)
是否有更简单的方法?
假设您想要所有“ err”列中的最大值,您可以这样做:
max(t[c].max() for c in t.colnames if 'err' in c)