Getting a list of indices where pandas boolean series is True

Using Boolean Indexing >>> s = pd.Series([True, False, True, True, False, False, False, True]) >>> s[s].index Int64Index([0, 2, 3, 7], dtype=”int64″) If need a np.array object, get the .values >>> s[s].index.values array([0, 2, 3, 7]) Using np.nonzero >>> np.nonzero(s) (array([0, 2, 3, 7]),) Using np.flatnonzero >>> np.flatnonzero(s) array([0, 2, 3, 7]) Using np.where >>> np.where(s)[0] … Read more