缺失值的处理

#缺失值的处理
from pandas import Series
import numpy as np
stringSer=Series(['a','b',np.nan,'d','e'])
#isnull 显示空值
stringSer.isnull()
#notnull 显示非空值
stringSer.notnull()
stringSer[stringSer.notnull()] #删除空值
stringSer.dropna() #删除空值
from pandas import DataFrame
df=DataFrame([[1.4,np.nan],[7.5,-4.5],[np.nan,np.nan],[0.75,-1.3]],index=['a','b','c','d'],columns=['one','two'])
df.dropna() #删除空值
df.dropna(how='all') #删除都为空值
df.fillna(0) #给空值填充0
df.fillna({'one':0,'two':-1}) #给one列填充0,给two列填充-1
df.fillna(df.mean()) #按均值填充

猜你喜欢

转载自www.cnblogs.com/tiankong-blue/p/11620980.html