简体   繁体   English

如何在另一列的pandas df列中获取与子字符串匹配的字符串?

[英]How do I get strings that match substrings in a pandas df column in another column?

I have a list of strings, Skills, and a pandas dataframe with descriptions in each row under column labeled "Job Summary". 我有一个字符串,技能和一个pandas数据框列表,其中每行描述标记为“作业摘要”。 I want to see if any of the strings in Skills are a substring in the "Job Summary" Column. 我想看看Skills中的任何字符串是否是“作业摘要”列中的子字符串。 If there are matches then to have the matching string appear in a column labeled Matches. 如果存在匹配,则匹配的字符串将出现在标记为匹配的列中。 If there is more than one then it should appear as a list of strings. 如果有多个,那么它应该显示为字符串列表。 Right now I have it so it tells me True or False, but I want the words themselves that match. 现在我有它,所以它告诉我是对还是错,但我希望这些单词本身匹配。

See what I currently have below 看看我目前在下面有什么

     #Sample list (Real list is much longer)
     Skills=['Science', 'Management','Equipment','Analysis']
     skills=list(map(str.lower,skills))

     joined='|'.join(skills)

     df['Matches']=df['Job Summary'].str.contains(joined)

results in df['Matches'] tell me True or False. 结果df ['匹配']告诉我是对还是错。 I want the word that matches 我想要匹配的单词

Using str.findall 使用str.findall

df=pd.DataFrame({'Job Summary':['Science Equipment','Analysis is Management']})
df['Job Summary'].str.findall('|'.join(Skills))
Out[95]: 
0      [Science, Equipment]
1    [Analysis, Management]
Name: Job Summary, dtype: object

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将一个 df 中的一列除以 pandas 中不同 df 中的另一列? - How do I divide one column in one df by another column in a different df in pandas? 如何根据另一个数据框的完整字符串列过滤 pandas dataframe 子字符串? - How can I filter a pandas dataframe of substrings based on another dataframe's column of full strings? 如何根据另一列中的值检查 pandas df 列值是否存在? - How do I check if pandas df column value exists based on value in another column? 如何将一个df的列条目匹配到另一个df; 如果它们相同,则将另一列的条目从第一个df附加到第二个df? - How do I match a column entry from one df to a different df; and if they're the same, append another column's entry from the first df to the 2nd df? 使用正则表达式解析pandas df列提取子字符串 - Parse pandas df column with regex extracting substrings Python - Pandas DF - 对与另一列中的条件匹配的列中的值求和 - Python - Pandas DF - sum values in a column that match a condition in another column 如何使用另一列中的一个键将pandas df与多列合并? - How do I merge pandas df with multiple columns using one key from another column? 如何将一些单元格值从 Pandas DF 中的 2 列移动到另一个新列? - How do I move some cell values from 2 columns in Pandas DF to another new column? 如何在熊猫列中获取唯一的子字符串 - How to get unique substrings in pandas column 如何在python / pandas中将一个df列中的字符串添加到另一个? - How do I add a piece of string from one df column to another in python/pandas?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM