Search for a value anywhere in a pandas DataFrame

后端 未结 3 853
时光说笑
时光说笑 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 03:53

    You should using isin , this is return the column , is want row check cold' answer :-)

    df.isin(['bal1']).any()
    A        False
    B         True
    C        False
    CLASS    False
    dtype: bool
    

    Or

    df[df.isin(['bal1'])].stack() # level 0 index is row index , level 1 index is columns which contain that value 
    0  B    bal1
    1  B    bal1
    dtype: object
    

提交回复
热议问题