pandas最重要的一个功能是,它可以对不同索引的对象进行算数运算.在对象相加时,如果存在不同的索引对,则结果的索引就是该索引对的并集. Series s1=Series([,3.4,1.5],index=['a','c','d','e']) s2=Series([-,3.1],index=['a','c','e','f','g']) s1 Out[]: a 7.3 c -25.0 d 3.4 e 1.5 dtype: float64 s2 Out[]: a -2.1 c 3.6 e -1.5
package main import "fmt" var a = 21.0 var b = 5.0 //var c float64 func main() { Arithmetic() // 算数运算 BitOperation() // 位运算 LogicalOperation() // 逻辑运算 Assignment() // 赋值运算 } func Arithmetic() { /* 算术运算符 */ fmt.Println(a + b) fmt.Println(a - b) f
1.python类与对象各个算术运算魔法方法总结: 2.各个魔法方法应用举例: 3.实例训练: (1)我们都知道在 Python 中,两个字符串相加会自动拼接字符串,但遗憾的是两个字符串相减却抛出异常.因此,现在我们要求定义一个 Nstr 类,支持字符串的相减操作:A – B,从 A 中去除所有 B 的子字符串. class Nstr(str): def __sub__(self,other): self=list(self) other=list(other) for i i