我的尝试:I was trying to remove the word 'MULTIPOLYGON', and parenthesis '(((', ')))'df['multi'] = df['multi'].str.replace(r"\(.*\)","")df['multi'] = df['multi'].map(lambda x: x.lstrip('MULTIPOLYGON()').rstrip('aAbBcC'))df.values =array([[''], [''], ... [''], [''], [''], ['7.5857754821 44.9628409423']所需的输出:df = multi3 11, 2 33 4 22, 5 6推荐答案尝试一下: import pandas as pdimport redef f(x): x = ' '.join(re.findall(r'[0-9, ]+',x)) return xdef f2(x): x = re.findall(r'[0-9, ]+',x) return pd.Series(x[0].split(','))df =pd.DataFrame({'a':['MULTIPOLYGON(((3 11, 2 33)))' ,'MULTIPOLYGON(((4 22, 5 6)))']})df['a'] = df['a'].apply(f)print(df)#or for different columns you can dodf =pd.DataFrame({'a':['MULTIPOLYGON(((3 11, 2 33)))' ,'MULTIPOLYGON(((4 22, 5 6)))']})#df['multi'] = df.a.str.replace('[^0-9. ]', '', regex=True)#print(df)list_of_cols = ['c1','c2']df[list_of_cols] = df['a'].apply(f2)del df['a']print(df)输出: a0 3 11, 2 331 4 22, 5 6 c1 c20 3 11 2 331 4 22 5 6[Finished in 2.5s] 这篇关于用 pandas 中的单词删除左括号和右括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!