问题
雷普雷克斯
我所拥有的
df1 = pd.DataFrame({'a': [1, 1, 2, 2, 3],
'b': ["NOSE PARKER Bond 1 Spain", "Fire PA1KER Bond 10 UK",
"NOSE 2HANDS Bond 3 FRANCE", "EARS STARKER Bond 11 SOUTH AFRICA",
"NORSEPACKER Bond 01 JAPAN2002"],
'c': [13, 9, 12, 5, 5]})
df1
我想要什么
df2 = pd.DataFrame({'a': [1, 1, 2, 2, 3],
'b': ["NOSE PARKER Bond 1 Spain", "Fire PA1KER Bond 10 UK",
"NOSE 2HANDS Bond 3 FRANCE", "EARS STARKER Bond 11 SOUTH AFRICA",
"NORSEPACKER Bond 01 JAPAN2002"],
'c': [13, 9, 12, 5, 5],
'b new': ["Bond 1", "Bond 10", "Bond 3", "Bond 11", "Bond 01"]})
df2
我的尝试
df1["b new"] = df1["b"].str.replace("[^Bond\s\d]", "").str.strip()
df1