Handle missing values

Process # missing values
from PANDAS Import Series
Import numpy AS NP
stringSer Series = ([ 'A', 'B', np.nan, 'D', 'E'])
#isnull displays a null value
stringSer.isnull ()
# notnull display non-null value
stringSer.notnull ()
stringSer [stringSer.notnull ()] # deleted null
stringSer.dropna () # remove nulls
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 () # remove null
df.dropna (how = 'all') # are deleted null
df.fillna (0) # to be filled with null 0
df.fillna ({ 'One' : 0, 'two': - 1}) # 0 to fill one column, two columns to fill -1
df.fillna (df.mean ()) according to the mean filling #

Guess you like

Origin www.cnblogs.com/tiankong-blue/p/11620980.html