0

I get the same indexing results using these two methods:

data.loc[data['loan_status']== 'Default'].head()

data[data['loan_status'].isin(['Default'])].head()

Is there an advantage of one over the other?

Also is there a reason why isin needs a ([]) parameter to work whereas most methods simply need a ()?

NimbleTortoise
  • 355
  • 5
  • 13

1 Answers1

0

.isin allows you to supply a list of values to check. For instance, if you were looking for 'Default' or Defaulted, or something like that, you could say:

data[data['loan_status'].isin(['Default', 'Defaulted'])].head()

Whereas otherwise, you would have to give it multiple conditions, like:

data.loc[(data['loan_status'] == 'Default') | (data['loan_status'] == 'Defaulted')]
sacuL
  • 49,704
  • 8
  • 81
  • 106
  • 1
    To summarise, for a single value use `==` or `pd.Series.eq`, multiple values use `pd.Series.isin`. – jpp Aug 09 '18 at 00:16