title: Find cosine similarity between different pandas dataframe
body: <p>I have three pandas dataframe, suppose group_1, group_2, group_3</p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd 
     group_1 = pd.DataFrame({'A':[1,0,1,1,1], 'B':[1,1,1,1,1]})
     group_2 = pd.DataFrame({'A':[1,1,1,1,1], 'B':[1,1,0,0,0]})
     group_3 = pd.DataFrame({'A':[1,1,1,1,1], 'B':[0,0,0,0,0]})
  </code></pre>
  <p>filled dummy value, all value will be binary for above group</p>
  <p>Now, there is another dataframe , new one</p>
  <pre class="lang-py prettyprint-override"><code>new_data_frame = pd.DataFrame({'A':[1,1,1,1,1], 'B':[0,0,0,0,0],'mobile': ['xxxxx','yyyyy','zzzzz','wwwww','mmmmmm']})
  new_data_frame.set_index('mobilenumber')
  
           A  B
   mobile     
   xxxxx  1   0
   yyyyy  1   0
   zzzzz  1   0
   wwwww  1   0
   mmmmmm 1   0
  </code></pre>
  <p>For each mobile in new_dataframe, I want to calculate mean cosine similarity(sum all score and divide by length of group dataframe), mobile number which have highest score will be assign to a particular group</p>
  <p>So my expected output will be</p>
  <pre><code>   mobile group
     xxxxx  group_1
     yyyyy  group_1
     zzzzz  group_3
     
  </code></pre>
  <p>something like this</p>
  <pre><code>  for x in new_data_frame.to_numpy():
        score = []
        for y in group_1.to_numpy():
           a =  cosine_similarity(x,y)
           score.append(a)
        mean_score = sum(score)/len(y)
  </code></pre>
  <p>I have added below code , is there a better way to achive this</p>
  <pre><code>def max_group(x,group_1, group_2, group_3 ):
      x_ = x.tolist()
      val =  x_[:-1]
  
      group = [group_1, group_2, group_3]
  
      score = []
      for i in range(len(group)):
          a = cosine_similarity([val], group[i].to_numpy())
          print('&lt;----&gt;')
          print(a.mean())
          score.append((a.mean(), i))
  
      return max(score[1])
   
   new_data_frame['group'] = new_data_frame.apply(lambda x: max_group(x, group_1, group_2, group_3), axis=1)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ZlYMJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZlYMJ.png" alt="enter image description here" /></a></p>