擅长:python、mysql、java
<p>最简单的方法是使用<a href="https://pandas.pydata.org/docs/reference/api/pandas.Series.replace.html" rel="nofollow noreferrer">^{<cd1>}</a>方法。正如文件指出的那样:</p>
<blockquote>
<p>This method has a lot of options. You are encouraged to experiment
and play with this method to gain intuition about how it works.</p>
</blockquote>
<pre><code>df['id'].replace(regex=out)
0 14
1 14
2 8
3 8
4 5
Name: id, dtype: int64
</code></pre>
<p>使用<code>out</code>作为:</p>
<pre><code>out= {
'see-dd': 14,
'sal-led': 8,
'dis-dd': 5
}
</code></pre>
<hr/>
<pre><code>df['pw'] = df['id'].replace(regex=out)
df
id status pw
0 see-dd-2333 y 14
1 see-dd-aaaaa y 14
2 sal-led-sss y 8
3 sal-led-sss n 8
4 dis-dd-red n 5
</code></pre>