擅长:python、mysql、java
<p>因为我们处理的是行级操作和字符串,所以没有一个向量化的方法来实现这一点</p>
<p>让我们使用<code>str.find</code>和<code>np.char.find</code>来创建数据帧</p>
<pre><code>#Note I've removed the spaces in your columns.
s = pd.DataFrame(df.apply(lambda x : x['ColA'].split(x['ColB']),axis=1).tolist())
idx = df.apply(lambda x : np.char.find(x['ColA'],x['ColB']),1)
pos = zip(idx.values, (idx - 1 + df["ColB"].str.len()).values)
df["Position"] = list(pos)
df['Proceeding Chars'], df['Following Chars'] = s[0], s[1]
print(df)
ColA ColB Position Proceeding Chars Following Chars
0 AGHXXXJ002 XXX (3, 5) AGH J002
1 AGHGHJJ002 GHJ (3, 5) AGH J002
2 ABCRTGHP001 RTGH (3, 6) ABC P001
3 ABCDFFP01 DFF (3, 5) ABC P01
4 ABCXGHJD09 XGH (3, 5) ABC JD09
5 HGMQQUTV01 HGM (0, 2) QQUTV01
6 GBHUJJS099 BHU (1, 3) G JJS099
</code></pre>