相关疑难解决方法(0)

按条件和列中的最小值过滤 Pandas 数据框

我有一个类似于

  test_a test_b  metric_e
0     OK    NOK        12
1     OK     OK         7
2     OK    NOK         2
3     OK     OK        55
Run Code Online (Sandbox Code Playgroud)

我想按一个条件过滤,这意味着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
Run Code Online (Sandbox Code Playgroud)

有没有办法在不必使用中间数据帧的情况下做到这一点?

python pandas

1
推荐指数
1
解决办法
5736
查看次数

标签 统计

pandas ×1

python ×1