擅长:python、mysql、java
<p>您可以使用<code>str.replace</code>的<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html" rel="nofollow noreferrer">case</a>参数,因为您已经提到了<code>regex=True</code></p>
<pre><code>dfMSR.apply(lambda x: x.astype(str).str.replace(r'\bna\b', 'N/A', regex=True,case=False))
</code></pre>
<p><em>请注意,如果它不是基于Regex的</em></p>
<p>输出:</p>
<pre><code>import pandas as pd
dfMSR = pd.DataFrame({'A':['NA','na','O', '', 'N/A'],
'B':['Anna','E','NA', 'Z', 'Na']})
dfMSR
A B
0 NA Anna
1 na E
2 O NA
3 Z
4 N/A Na
dfMSR.apply(lambda x: x.astype(str).str.replace(r'\bna\b', 'N/A', regex=True,case=False))
A B
0 N/A Anna
1 N/A E
2 O N/A
3 Z
4 N/A N/A
</code></pre>