title: Finding similar groups based on an intersection of values in a different column
body: <p>I have a df that looks like this:</p>
  
  <pre><code>Group   Attribute
  
  Cheese  Dairy
  Cheese  Food
  Cheese  Curd
  Cow     Dairy
  Cow     Food
  Cow     Animal
  Cow     Hair
  Cow     Stomachs
  Yogurt  Dairy
  Yogurt  Food
  Yogurt  Curd
  Yogurt  Fruity
  </code></pre>
  
  <p>What I'd like to do for each group is find the group that it's most like, based on the intersection of Attributes. The end form I'd like is:</p>
  
  <pre><code>Group   TotalCount   LikeGroup   CommonWords  PCT
  
  Cheese  3            Yogurt      3            100.0
  Cow     5            Cheese      2            40.0
  Yogurt  4            Cheese      4            75.0
  </code></pre>
  
  <p>I realize this might be asking a lot in one question. I can do much of it but I'm really lost on getting a count for the intersection of Attributes, even between just one Group and another. If I could find the intersection count between Cheese and Yogurt that would send me in the right direction.</p>
  
  <p>Is it possible to do it within the dataframe? I can see making several lists and doing intersections between all pairs of lists, then using the new list lengths to get the percentages.</p>
  
  <p>For instance, for Yogurt: </p>
  
  <pre><code>&gt;&gt;&gt;Yogurt = ['Dairy','Food','Curd','Fruity']
  &gt;&gt;&gt;Cheese = ['Dairy','Food','Curd']
  
  &gt;&gt;&gt;Yogurt_Cheese = len(list(set(Yogurt) &amp; set(Cheese)))/len(Yogurt)
  0.75
  
  &gt;&gt;&gt;Yogurt = ['Dairy','Food','Curd','Fruity']
  &gt;&gt;&gt;Cow = ['Dairy','Food','Animal','Hair','Stomachs']
  
  &gt;&gt;&gt;Yogurt_Cow = len(list(set(Yogurt) &amp; set(Cow)))/len(Yogurt)
  0.5
  
  &gt;&gt;&gt;max(Yogurt_Cheese,Yogurt_Cow)
  0.75
  </code></pre>