【发布时间】:2017-04-19 02:23:52
【问题描述】:
我有一个字符串列 ('b'),并希望在同一列中获取类似于子字符串的字符串。例如,在下面的数据框列 'b' 中,world 是 helloworld 的子字符串,ness 是 greatness 的子字符串。我想在列表中列出字符串 world 和 ness。能否请您提出解决方案。
a b
0 test world
1 teat helloworld
2 gor bye
3 jhr greatness
4 fre ness
列表中的所需输出
listofsubstrings
Out[353]: ['world', 'ness']
【问题讨论】:
-
你可以使用方法str.find(seach_str)。如果找到则返回 + 号,否则返回 -1
-
我想你需要遍历 b 并检查每个值是否是 b 中另一个值的子字符串(使用类似 @anonyXmous 建议的东西)。顺便说一句,这可能需要一段时间,所以希望您的数据框不会太大
标签: python python-2.7 pandas dataframe