【发布时间】:2021-10-16 02:49:34
【问题描述】:
找到了这个link,我的工作有点相似。
说我有:
x = ['the', 'the', 'and', 'a', 'apple', 'heart', 'heart']
y = {'words': ['the', 'belt', 'computer', 'heart','and'],'values':[3,2,1,1,4]}
使用上面链接中的建议,我得到了这个:
df = pd.DataFrame.from_dict(y)
items = set(df['words'])
found = [i for i in x if i in items]
print(found)
结果是: ['the', 'the', 'and', 'heart', 'heart']
我希望能够得到单词的对应值,我卡住了。我想要的结果是这样的:
[3,3,4,1,1]
关于如何实现这一目标的任何想法?将不胜感激。
【问题讨论】:
标签: python dataframe intersection