import numpy as np import pandas as pd a=np.array([1,2,3]) b=np.array([3]) print(a+b)#[4 5 6] 只要列一致,广播,每个都加 s=pd.Series([1,2,3,4]) print(s+1)#Series与数组的假发,每个都加 s2=pd.Series([2]) print(s+s2)#仅匹配一个 print(s.add(s2,fill_value=0))#仅匹配一个,其余加0 df1=pd.DataFrame({"A":[1,2,3], "B":[7,8,9]}) df2=pd.DataFrame({"B":[1,2,3], "C":[7,8,9]}) print(df1.add(df2))#匹配的相加,不匹配的NaN print(df1.add(df2,fill_value=0))#匹配的相加,其余加0
来源:https://www.cnblogs.com/wcyMiracle/p/12446253.html