擅长:python、mysql、java
<p>您可以将<code>str.lower()</code>与<code>.replace</code>链接,而且不需要测试<code>if</code>条件,因为它是在替换中隐式执行的:</p>
<pre><code>dfMSR = dfMSR.apply(lambda x: x.str.lower()).replace(oldtxt, newtxt, regex=True)
</code></pre>
<p>在一个示例中,它将如下所示:</p>
<pre><code>pd.DataFrame({'A':['NA','na','O'],
'B':['X','E','NA']}).apply(lambda x: x.str.lower()).replace('na','N/A',regex=True)
</code></pre>