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
Post a Comment