擅长:python、mysql、java
<p>正则表达式不太正确-如果括号中有空格怎么办</p>
<pre><code>import pandas as pd
s = pd.Series(['Cuba (Island of Caribeas)', 'Andorra(no mentioned)', 'Algeria'])
s.replace(r" ?\((?:\w+ ?)+\)", "", regex=True)
</code></pre>
<p>这将返回:</p>
<pre><code>Out[13]:
0 Cuba
1 Andorra
2 Algeria
dtype: object
</code></pre>
<p>要使其适应您的示例:</p>
<pre><code>df['Country'] = df['Country'].replace(r" ?\((?:\w+ ?)+\)", "", regex=True)
</code></pre>