Pandas boolean indexing: Selecting series items with a mask

Pandas boolean indexing: Selecting series items with a mask

Retrieve selected items from a Python Pandas series by broadcasting a condition, then using it as a boolean (“mask”) index:

s = pd.Series([10, 20, 30], index=list('abc'))
s >= 20          # [False, True, True]
s.loc[ s >= 20 ] # returns [20, 30]