Pythonic Way to have multiple Or's when conditioning in a dataframe

后端 未结 1 1255
醉梦人生
醉梦人生 2021-01-23 01:24

Basically instead of writing

data[data[\'pos\'] == \"QB\" | data[\'pos\'] == \"DST\" | ...]

where there are many cases I want to check

相关标签:
1条回答
  • 2021-01-23 01:58

    What you are looking for is Series.isin . Example -

    data[data['pos'].isin(("QB", "DST", ...))]
    

    This would check if each value from pos is in the list of values - ("QB", "DST", ...) . Similar to what your multiple | would do.

    0 讨论(0)
提交回复
热议问题