检查列表中是否存在单词以及是否存在字符串整数



这个想法是找到特定的单词,无论是否存在于句子列表中。

另外,作为另一个输出,查找字符串整数。

查找列表中单词的代码

import pandas as pd
import re
info = ['Crafting a compelling job description is essential to helping you attract the most qualified candidates for your job. With more than 25 million jobs listed on Indeed, a great job description can help your jobs stand out from the rest. Your job descriptions are where you start marketing your company and your job to your future hire.']
df = pd.DataFrame(info,columns=['One'])
df['New_Col'] = df.One.str.contains('jobs', flags = re.IGNORECASE, regex = True, na = False)

save = []
for i,e in enumerate(info):
save.append(e.isdigit())
df['New_Col2'] = save

输出:

info
Out[40]: ['Crafting a compelling job description is essential to helping you attract the most qualified candidates for your job. With more than 25 million jobs listed on Indeed, a great job description can help your jobs stand out from the rest. Your job descriptions are where you start marketing your company and your job to your future hire.']

输出

One  New_Col  New_Col2
0  Crafting a compelling job description is essen...     True     False

总结:理想情况下,以一种我只向regex提供应该查找的单词列表的方式自动化它会很好。(例如["jobs"、"employment"]等(,这可以通过格式化函数完成并循环使用。然而,我不是regex的铁杆粉丝,可能应用该函数会更有意义。总而言之,任何解决这一问题的更好方法都是有益的

您可以进行

code  = "One Two Three n59 results 46"
res = [int(s) for s in code .split() if s.isdigit()]
print(res)

结果:

[59, 46]

最新更新