python - Check if a value is in a list of columns in a pandas.DataFrame -


i working data looks (simplified) in pandas.dataframe:

|-----------|-----------|-----------| | feature 1 | feature 2 | feature 3 | |-----------|-----------|-----------| |         |     b     |     d     | |         |         |     b     | |         |     d     |         | |         |     b     |         | |         |         |         | |         |         |     d     | |-----------|-----------|-----------| 

and want create new column answer question "is value 'd' present in of columns?"

so final data like:

|-----------|-----------|-----------|-----------| | feature 1 | feature 2 | feature 3 | feature 4 | |-----------|-----------|-----------|-----------| |         |     b     |     d     |    true   | |         |         |     b     |   false   | |         |     d     |         |    true   | |         |     b     |         |   false   | |         |         |         |   false   | |         |         |     d     |    true   | |-----------|-----------|-----------|-----------| 

i've tried using df.isin() method, i'm still not able this.

do guys know how this?

try approach:

df[df=='d'].any(1) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -