检查列中的单词是否与字典中的单词匹配

时间:2021-05-31 06:27:43

标签: python-3.x append string-matching

data snapshot

大家好, 我是 python 编程的新手。我有一组列的数据,如图所示。每个职业都有相关的硬技能,但它实际上是硬技能和技术技能的结合。我的目标是创建一个新列,将每项技能分类为困难或技术,以便我以后更容易过滤。我创建了一本技术技能词典。我想检查字典单词和硬技能列单词之间是否匹配。你能帮我写代码吗?字典词如下:

dict = {tech_skills:['Android(操作系统)','Apple IOS','Apple iPhone','电脑键盘','电脑终端','Corel Wordperfect Office','FaceTime', “Gmail”、“Google Apps”、“Google 文档”、“Google 语音”、“Google+”、“Microsoft Excel”、“Microsoft Internet Explorer”、“Microsoft Office”、“Microsoft Outlook”、“Microsoft PowerPoint”、“ Microsoft Visio'、'Microsoft Windows'、'Microsoft Windows NT'、'Microsoft Windows XP'、'Microsoft Word'、'移动设备'、'Skype'、'Tableau(商业智能软件)']}< /p>

1 个答案:

答案 0 :(得分:0)

# Copy hard_skills_name onto a new column
df['matched'] = df['hard_skills_name']

# replace with 1 if matched with the techskills
df['matched'].replace(dict['tech_skills'],1,inplace=True)

# replace non-matched with 0
df['matched'][df['matched'] != 1] = 0   

然后您可以检查匹配的数据框:

print(df[df['matched']=1])
相关问题