title: Filtering rows from pandas dataframe using concatenated strings
body: <p>I have a pandas dataframe plus a pandas series of identifiers, and would like to filter the rows from the dataframe that correspond to the identifiers in the series. To get the identifiers from the dataframe, I need to concatenate its first two columns. I have tried various things to filter, but none seem to work so far. Here is what I have tried:</p>
  
  <p>1) I tried adding a column of booleans to the data frame, being true if that row corresponds to one of the identifiers, and false otherwise (hoping to be able to do filtering afterwards using the new column):</p>
  
  <pre><code>df["isInAcids"] = (df["AcNo"] + df["Sortcode"]) in acids
  </code></pre>
  
  <p>where</p>
  
  <pre><code>acids
  </code></pre>
  
  <p>is the series containing the identifiers.</p>
  
  <p>However, this gives me a </p>
  
  <pre><code>TypeError: unhashable type
  </code></pre>
  
  <p>2) I tried filtering using the apply function:</p>
  
  <pre><code>df[df.apply(lambda x: x["AcNo"] + x["Sortcode"] in acids, axis = 1)]
  </code></pre>
  
  <p>This doesn't give me an error, but the length of the data frame remains unchanged, so it doesn't appear to filter anything.</p>
  
  <p>3) I have added a new column, containing the concatenated strings/identifiers, and then try to filter afterwards (see <a href="https://stackoverflow.com/questions/12065885/how-to-filter-the-dataframe-rows-of-pandas-by-within-in">Filter dataframe rows if value in column is in a set list of values</a>):</p>
  
  <pre><code>df["ACIDS"] = df["AcNo"] + df["Sortcode"]
  df[df["ACIDS"].isin(acids)]
  </code></pre>
  
  <p>But again, the dataframe doesn't change.</p>
  
  <p>I hope this makes sense...</p>
  
  <p>Any suggestions where I might be going wrong?
  Thanks,
  Anne</p>