当前位置: 移动技术网 > IT编程>脚本编程>Python > pandas 将索引值相加的方法

pandas 将索引值相加的方法

2018年11月30日  | 移动技术网IT编程  | 我要评论

魔窟斗智,腾讯名人坊陈晓,免费网盘

如下所示:

 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 将索引值相加的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网