title: invalid type comparison with Booleans in Pandas
body: <p>Trying to clean Country (Ctry) column in pandas dataframe (origin) based on other row level data, or other dataframes with similar data. See links for example data frames.</p>
  
  <p>It will eventually feed two new columns in the dataframe giving correctly formatted country and a data quality "score".</p>
  
  <p><a href="https://i.stack.imgur.com/xpzTh.png" rel="nofollow noreferrer">Origin Dataframe</a>
  <a href="https://i.stack.imgur.com/NF2gR.png" rel="nofollow noreferrer">Nafta, Countries, and States DataFrames</a></p>
  
  <p>The function works on values that are in the lookup tables, or blanks, but when I pass "bad" data in, it gives a invalid type comparison. Testing this separately returns a boolean and works:</p>
  
  <pre><code>Nafta.loc[Nafta[col] == a].empty .
  </code></pre>
  
  <p>Not sure why this doesn't work.  I've tested the values, and its Boolean to Boolan.  See custom function and lambda.</p>
  
  <pre><code>def CountryScore(a,b,c): 
      if pd.isnull(a):
          score = "blank"
          if pd.notnull(b):
              for col in States:
                  if States.loc[States[col]== b].empty != True:
                      corfor = States.iloc[States.loc[States[col] == b].index[-1],2]
                      break
                  else:
                      corfor = "Bad Data"
                      continue
          elif pd.notnull(c):
              if (len(str(c).strip()) &lt;= 5) or (len(str(c).strip()) &gt; 9):
                  corfor = "USA"
              else:
                  corfor = "CAN"
          else:
              corfor = "Bad Data"
      else:
          for col in Nafta:
              if Nafta.loc[Nafta[col] == a].empty != True:
                  score = "good" 
                  corfor = Nafta.iloc[Nafta.loc[Nafta[col] == a].index[-1],1]
                  break
              else:
                  score = "pending"
                  continue
      if  "pending" == score:
          for col in Country:
              if Country.loc[Country[col]== a].empty != True:
                  score = "good"
                  corfor = Country.iloc[Country.loc[Country[col] == a].index[-1],2]
                  break
              else:
                  score = "bad"
                  corfor = "Bad Data"
                  continue
      return score, corfor
  
  origin["Origin Ctry Score"] , origin["Origin Ctry Format"] = zip(*origin.apply(lambda x: CountryScore(x["Origin Ctry"], x["Origin State"], x["Origin Zip"]), axis = 1))
  </code></pre>
  
  <p>Assume dataframes are loaded already.  Thanks!!!</p>