s2=Series([1,2,3],index=['A','B','C'])
s3=Series([4,5,6,7],index=['B','C','D','E'])
s2+s3
s2:
A 1
B 2
C 3
dtype: int64
s3:
B 4
C 5
D 6
E 7
dtype: int64
s2+s3
A NaN
B 6.0
C 8.0
D NaN
E NaN
dtype: float64
DataFrame加法
df1 = dframe(np.arange(4).reshape(2,2),index=['A','B'],columns=['BJ','SH'])
df2 = dframe(np.arange(9).reshape(3,3),index=['A','B','C'],columns=['BJ','SH','GZ'])
df1:
BJ SH
A 0 1
B 2 3
df2:
BJ SH GZ
A 0 1 2
B 3 4 5
C 6 7 8
df2+df3
BJ GZ SH
A 0.0 NaN 2.0
B 5.0 NaN 7.0
C NaN NaN NaN
df3 = dframe([[1,2,3],[4,5,np.nan],[7,8,9]],index=['AA','BB','CC'],columns=['a','b','c'])
df3:
a b c
AA 1 2 3.0
BB 4 5 NaN
CC 7 8 9.0
df3.sum() #按行求和
a 12.0
b 15.0
c 12.0
dtype: float64
df3.sum(axis=1) #按列求和
AA 6.0
BB 9.0
CC 24.0
dtype: float64
df3.min()
a 1.0
b 2.0
c 3.0
dtype: float64
df3.max()
a 7.0
b 8.0
c 9.0
dtype: float64
df3.describe()
a b c
count 3.0 3.0 2.000000
mean 4.0 5.0 6.000000
std 3.0 3.0 4.242641
min 1.0 2.0 3.000000
25% 2.5 3.5 4.500000
50% 4.0 5.0 6.000000
75% 5.5 6.5 7.500000
max 7.0 8.0 9.000000