Suppose I have two columns in a python pandas.DataFrame:
col1 col2
item_1 158 173
item_2 25 191
item_3 180 33
item_4 152 165
item_5 96 108
What's the best way to take the cosine similarity of these two columns?
Is that what you're looking for?
from scipy.spatial.distance import cosine
from pandas import DataFrame
df = DataFrame({"col1": [158, 25, 180, 152, 96],
"col2": [173, 191, 33, 165, 108]})
print(1 - cosine(df["col1"], df["col2"]))