圆月山庄资源网 Design By www.vgjia.com

如下所示:

 s1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
 s2 = pd.Series([10, 20, 30, 40], index=['a', 'b', 'c', 'd'])
 print s1 + s2
a 11
b 22
c 33
d 44
dtype: int64
 s1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
 s2 = pd.Series([10, 20, 30, 40], index=['b', 'd', 'a', 'c'])
 print s1 + s2
a 31
b 12
c 43
d 24
dtype: int64
 s1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
 s2 = pd.Series([10, 20, 30, 40], index=['c', 'd', 'e', 'f'])
 print s1 + s2
a  NaN
b  NaN
c 13.0
d 24.0
e  NaN
f  NaN
dtype: float64
 s1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
 s2 = pd.Series([10, 20, 30, 40], index=['e', 'f', 'g', 'h'])
 print s1 + s2
a NaN
b NaN
c NaN
d NaN
e NaN
f NaN
g NaN
h NaN
dtype: float64

以上这篇pandas 将索引值相加的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

标签:
pandas,索引值,相加

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com