擅长:python、mysql、java
<p>这里有一种使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.extract.html" rel="nofollow noreferrer">^{<cd1>}</a>的方法:</p>
<pre><code>df['Country'] = (df.Name.str.lower()
.str.extract(r'inf(.*?)_')
.replace('', float('nan'))
.fillna('No_Country'))
</code></pre>
<hr/>
<pre><code>print(df)
Name Country
0 inf.negem.netmgmt No_Country
1 infbe_cdb be
2 inf_igh No_Country
3 INF_EONLOG No_Country
4 inf.dkprime.netmgmt No_Country
5 infaus_mgo aus
6 infau_abr au
</code></pre>