Pandas Series缺失值补充

如何去除NAN(not a number):

dropna

fillna

add及fill_value

#当计算结果为NAN时,需要用特定的值来补充代替
import pandas as pd
s1=pd.Series([1,2,3,4],index=['a','b','c','d'])
s2=pd.Series([10,20,30,40],index=['c','d','e','f'])
s3=pd.Series([1,2,3,4],index=['a','b','c','d'])
s4=pd.Series([10,20,30,40],index=['c','d','e','f'])
print (s1+s2) #--1--直接相加只有索引c\d对应有值
print ((s1+s2).dropna())#--2--去除值为空的
print ((s1+s2).fillna(0))#--3--把值为空的地方填充成0
print (s1.add(s2,fill_value=1)) #--4--s1和s2相加,当索引对应值不存在,用1代替s2中元素和s1相加
-----------1------------
a     NaN
b     NaN
c    13.0
d    24.0
e     NaN
f     NaN
dtype: float64
----------2--------------
c    13.0
d    24.0
dtype: float64

-----------3--------------
a     0.0
b     0.0
c    13.0
d    24.0
e     0.0
f     0.0
dtype: float64

-----------4---------------
a     2.0
b     3.0
c    13.0
d    24.0
e    31.0
f    41.0
dtype: float64
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值