我有一个类似于Dataframe的数据结构
test_a test_b metric_e
0 OK NOK 12
1 OK OK 7
2 OK NOK 2
3 OK OK 55
我希望通过一个条件进行筛选,即 test_a == OK
并捕获 metric_e
的最小值。我可以通过复制数据框来实现这一目标,只需两行代码:
df_t = df[df.test_a == 'OK'].reset_index(drop=True)
df_t.iloc[df_t.metric_e.idxmin()].to_frame()
test_a | test_b | metric_e
OK | NOK | 2
有没有一种方法可以不使用中间数据框来完成这个操作?