Search for a value anywhere in a pandas DataFrame

后端 未结 3 852
时光说笑
时光说笑 2020-12-24 03:45

This seems like a simple question, but I couldn\'t find it asked before (this and this are close but the answers aren\'t great).

The question is: if I want to searc

3条回答
  •  一向
    一向 (楼主)
    2020-12-24 04:13

    You can perform equality comparison on the entire DataFrame:

    df[df.eq(var1).any(1)]
    

    Another option is using numpy comparison:

    df[(df.values.ravel() == var1).reshape(df.shape).any(1)]
    

提交回复
热议问题