如何从 pandas 数据框中选择的列表中检查值? [英] How to check if a value is in the list in selection from pandas data frame?

查看:73
本文介绍了如何从 pandas 数据框中选择的列表中检查值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来很丑:

df_cut = df_new[
             (
             (df_new['l_ext']==31) |
             (df_new['l_ext']==22) |
             (df_new['l_ext']==30) |
             (df_new['l_ext']==25) |
             (df_new['l_ext']==64)
             )
            ]

不起作用:

df_cut = df_new[(df_new['l_ext'] in [31, 22, 30, 25, 64])]

是否存在上述问题"的优雅且可行的解决方案?

Is there an elegant and working solution of the above "problem"?

推荐答案

使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆