1 回答
TA贡献1820条经验 获得超2个赞
创建一个替换系列,然后与可选参数一起s使用,将 中的值替换为 中的相应值:Series.replaceregex=TrueRepStrs
s = df.set_index('KeyStr')['ValStr']
s.index = r'(?:(?<=;\s)|(?<=^))' + s.index + r'(?=;|$)'
df['RepStr'] = df['RepStr'].replace(s, regex=True)
0 Sean Connery
1 Sean Connery
2 Sean Connery
3 Sean Connery; Ernst Stavro Blofeld
4 Sean Connery; Roger Moore; Ernst Stavro Blofeld
5 R Moore R
6 Roger Moore
7 Roger Moore
8 Ernst Stavro Blofeld; Sean Connery; Roger Moore
9 Ernst Stavro Blofeld; Sean Connery
10 Ernst Stavro Blofeld
11 Ernst Stavro Blofeld
12 Ernst Stavro Blofeld; Sean Connery
Name: RepStr, dtype: object
添加回答
举报