title: Python - Finding the top 5 rows containing a word in a dataframe
body: <p>I'm trying to make a function that prints the top 5 products and their prices, and the bottom 5 products and their prices of the product listings that contain words from a wordlist. I've tried making it like this -     </p>
  
  <pre><code>def wordlist_top_costs(filename, wordlist):
      xlsfile = pd.ExcelFile(filename)
      dframe = xlsfile.parse('Sheet1')    
      dframe['Product'].fillna('', inplace=True)
      dframe['Price'].fillna(0, inplace=True)
      price = {}
      for word in wordlist:
          mask = dframe.Product.str.contains(word, case=False, na=False)
          price[mask] = dframe.loc[mask, 'Price']
  
      top = sorted(Score.items(), key=operator.itemgetter(1), reverse=True)
      print("Top 10 product prices for: ", wordlist.name)
      for i in range(0, 5):
          print(top[i][0], "  |  ", t[i][1])  
  
      bottom = sorted(Score.items(), key=operator.itemgetter(1), reverse=False)
      print("Bottom 10 product prices for: ", wordlist.name)
      for i in range(0, 5):
          print(top[i][0], "  |  ", t[i][1])
  </code></pre>
  
  <p>However, the above function throws an error at line 
  <code>price[mask] = dframe.loc[mask, 'Price in AUD']</code> that says -
  <code>TypeError: 'Series' objects are mutable, thus they cannot be hashed</code>
  Any help to correct/modify this appreciated. Thanks!</p>
  
  <p>Edit -
  For eg.
  wordlist - alu, co, vin </p>
  
  <p>Product | Price</p>
  
  <ul>
  <li><p>Aluminium Crown - 22.20</p></li>
  <li><p>Coca Cola - 1.0</p></li>
  <li><p>Brass Box - 28.75</p></li>
  <li><p>Vincent Kettle - 12.00</p></li>
  <li><p>Vinyl Stickers - 0.50</p></li>
  <li><p>Doritos - 2.0</p></li>
  <li><p>Colin's Hair Oil - 5.0</p></li>
  <li><p>Vincent Chase Sunglasses - 75.40</p></li>
  <li><p>American Tourister - $120.90</p></li>
  </ul>
  
  <p>Output :</p>
  
  <p>Top 3 Product Prices:</p>
  
  <p>Vincent Chase Sunglasses - 75.40</p>
  
  <p>Aluminium Crown - 22.20</p>
  
  <p>Vincent Kettle - 12.0</p>
  
  <p>Bottom 3 Product Prices:</p>
  
  <p>Vinyl Stickers - 0.50</p>
  
  <p>Coca Cola - 1.0</p>
  
  <p>Colin's Hair Oil - 5.0</p>