【问题标题】:Check if the words in a column matches the words in a dictionary检查列中的单词是否与字典中的单词匹配
【发布时间】:2021-08-18 11:20:30
【问题描述】:

data snapshot

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

dict = {tech_skills:['Android(操作系统)','Apple IOS','Apple iPhone','电脑键盘','电脑终端','Corel Wordperfect Office','FaceTime', 'Gmail'、'Google Apps'、'Google Docs'、'Google Voice'、'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(商业智能软件)']}

【问题讨论】:

  • 到目前为止你尝试过什么?

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


【解决方案1】:
# 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])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    相关资源
    最近更新 更多