title: Cosine similarity between each row in a Dataframe in Python
body: <p>I have a DataFrame containing multiple vectors each having 3 entries. Each row is a vector in my representation. I needed to calculate the cosine similarity between each of these vectors. Converting this to a matrix representation is better or is there a cleaner approach in DataFrame itself?</p>
  
  <p>Here is the code that I have tried.</p>
  
  <pre><code>import pandas as pd
  from scipy import spatial
  df = pd.DataFrame([X,Y,Z]).T
  similarities = df.values.tolist()
  
  for x in similarities:
      for y in similarities:
          result = 1 - spatial.distance.cosine(x, y)
  </code></pre>