2

Basically instead of writing

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

where there are many cases I want to check

I was trying to do something similar to this What's the pythonic method of doing multiple ors?. However, this

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

doesn't work.

I read the documentation here http://pandas.pydata.org/pandas-docs/stable/gotchas.html but I'm still having issues.

Community
  • 1
  • 1
qwertylpc
  • 2,016
  • 7
  • 24
  • 34

1 Answers1

2

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.

Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176