擅长:python、mysql、java
<p>一种可能的方法是使用<a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.mask.html" rel="nofollow noreferrer">^{<cd1>}</a>,这将替换一个值,其中一个条件是<code>True</code>。如果你循环你的条件和价值观,我想你得到了你需要的</p>
<pre><code>conditions = [(df == 0)| (df.isnull==False),
(df == 8)| (df.isnull==True),
(df == 6)| (df.isnull==False)]
values = [999,444,555]
for condition, value in zip(conditions, values):
df.mask(condition, value, inplace=True)
</code></pre>
<p>您的示例的输出如下</p>
<pre><code> B1 B2 B3 B4 B5
0 9 999 5 555 7
1 444 7 555 4 444
2 999 9 444 555 555
3 1 999 7 555 3
</code></pre>