擅长:python、mysql、java
<p>您可以使用<code>np.where()</code>,它比lambda性能更好,我认为:</p>
<pre><code>data["ProtocolTCP"] = np.where(data["ProtocolTCP"].startswith("tcp-"),data["ProtocolTCP"].str.replace("tcp-","tcp "),data["ProtocolTCP"])
</code></pre>
<p>使用列表理解的另一个选项:</p>
<pre><code>data["ProtocolTCP"] = [x.replace("tcp-","tcp ") if x.startswith("tcp-") for x in data["ProtocolTCP"].values]
</code></pre>