擅长:python、mysql、java
<p>使用<code>np.where</code>:</p>
<pre><code>In [3]:
df['z'] = np.where(df['y'].isnull(), df['x'], df['y'])
df
Out[3]:
x y z
0 1 NaN 1
1 2 8 8
2 4 10 10
3 8 NaN 8
</code></pre>
<p>这里它使用布尔条件,如果true返回<code>df['x']</code>否则<code>df['y']</code></p>