如下所示:
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 11b 22c 33d 44dtype: 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 31b 12c 43d 24dtype: 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 NaNb NaNc 13.0d 24.0e NaNf NaNdtype: 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 NaNb NaNc NaNd NaNe NaNf NaNg NaNh NaNdtype: float64
以上这篇pandas 将索引值相加的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林站长站。
新闻热点
疑难解答