Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 多个系列中的子串_Python_String_Pandas - Fatal编程技术网

Python 多个系列中的子串

Python 多个系列中的子串,python,string,pandas,Python,String,Pandas,我试图找到一种方法来搜索字符串中的子字符串,以解决这样的问题 findin = pd.Series({1:'abcab', 2: 'abab',3: 'abcdaa', 4:'cabca'}) what = pd.Series({1:'b',2: 'a',3: 'bc',4: 'abc'}) 其中“what”是我正在寻找的,而“findin”是我想要搜索的值 我希望输出类似于 1 4 0 3 1 1 我尝试过的每一种方法都会因为出现的值的数量不同而感到不安。我不断得到“数据必须是一维的”,

我试图找到一种方法来搜索字符串中的子字符串,以解决这样的问题

findin = pd.Series({1:'abcab', 2: 'abab',3: 'abcdaa', 4:'cabca'})
what = pd.Series({1:'b',2: 'a',3: 'bc',4: 'abc'})
其中“what”是我正在寻找的,而“findin”是我想要搜索的值 我希望输出类似于

1 4
0 3 
1
1
我尝试过的每一种方法都会因为出现的值的数量不同而感到不安。我不断得到“数据必须是一维的”,例如使用如下方法

list(map(lambda x, y: x.find(y), findin, what))

我觉得expand需要在这里,但它去哪里了?

您可以在函数中使用regex,并在
findin
系列中应用:

c = iter(range(1, 5))

def func(x):
    ind = next(c)
    return [i.start() for i in re.finditer(what[ind], x)]

findin.apply(func)
输出:


不清楚你是如何得到你的产出的。您能详细解释一下吗?输出是字符串“findin”中子字符串“what”的位置,谢谢!这正是我想要的!我需要和ITER成为更好的朋友。。。。
1    [1, 4]
2    [0, 2]
3       [1]
4       [1]
dtype: object