擅长:python、mysql、java
<p>由于pandas中的<a href="http://pandas.pydata.org/pandas-docs/stable/dsintro.html?highlight=alignment#intro-to-data-structures" rel="nofollow noreferrer">intrinsic data alignment</a>,您可以将<code>add</code>与<code>fill_value=0</code>一起使用,它将基于索引对齐对这两个序列进行求和。</p>
<pre><code>df1.add(df2,fill_value=0)
</code></pre>
<p>输入:</p>
<pre><code>df1 = pd.Series([10]*4,index=[0,1,3,4])
df2 = pd.Series([10,12,15,20], index=[0,1,2,4])
df1.add(df2,fill_value=0)
</code></pre>
<p>输出:</p>
<pre><code>0 20.0
1 22.0
2 15.0
3 10.0
4 30.0
dtype: float64
</code></pre>