【发布时间】:2021-01-08 15:27:29
【问题描述】:
我有一个类似的数据框
title titlenew
0 Two Workers Are Struck By Motor Vehicle And O... two workers are struck by motor vehicle and o...
1 Foreman Is Fatally Crushed When Forklift Tips... foreman is fatally crushed when forklift tips...
2 Employee Suffers Abdominal Fracture In Fall F... employee suffers abdominal fracture in fall f...
3 Employee'S Body Is Caught In Asphalt Machine ... employee's body is caught in asphalt machine ...
4 Employee Is Punctured In Abdomen With Nail employee is punctured in abdomen with nail
我转换为向量用于 NLP 处理。它们现在看起来像
card2vec_title card2vec_titlenew
0 [0.09446411579847336, 0.18325935304164886, 0.1... [0.01013200543820858, -0.015507892705500126, 0...
1 [0.11135150492191315, 0.16989260911941528, 0.1... [0.0871051624417305, 0.07891112565994263, -0.0...
2 [-0.019224125891923904, 0.3285079598426819, -0... [0.052899472415447235, 0.2530696988105774, -0....
3 [0.06179530546069145, 0.10462947934865952, 0.0... [0.05848287418484688, 0.062050893902778625, -0...
4 [0.0604548417031765, 0.2742682993412018, -0.00... [0.09018705040216446, 0.23053207993507385, -0.
我的问题是,我怎样才能找到这两列的相关分数(或余弦相似度)。执行df.card2vec_titlenew.corr(df.card2vec_title) 会出现错误提示
/ 不支持的操作数类型:'list' 和 'int'
我的问题是相关性,因此没有提供我如何将字符串转换为向量的代码。帮助表示赞赏。谢谢
【问题讨论】:
-
这里有什么帮助吗?
-
显示您的代码。您应该能够从数据帧 sns.heatmap(weights_df.corr(), center=0, cmap=cmap, linewidths=1, annot=True, fmt=".2f") 运行 corr 并将其发送到热图。 mask = np.triu(np.ones_like(corr, dtype=bool)) sns.heatmap(corr, cmap=cmap, center=0, linewidths=1, annot=True, fmt=".2f",mask=mask)
标签: python pandas nlp cosine-similarity