Filter elements

About filter used in conjunction with:

notnull with all isnull with any

For example: filter to obtain useful data for the following data

Method a: null exclusion

Import PANDAS AS PD 

Import numpy AS NP 

from PANDAS Import Series, DataFrame 

DF = DataFrame (Data = np.random.randint (10, 60, size = (8, 8 ))) 

df.iloc [ l, 3] = None 
DF .iloc [ 2,6] = None 
df.iloc [ 4,1] = None 
df.iloc [ 5,6] = np.nan 

DF 

df.notnull (). all (Axis =. 1)                       # is not empty of all Boolean record index 

df.loc [df.notnull (). All (Axis =. 1)]               # the index value 

df.loc [df.isnull (). the any (Axis =. 1)]                # null values recorded Article number

 Directly call dropna removal method to perform a null value

df.dropna(axis=0)

Method two: filled with the current value

df.fillna (Method = ' ffill ' , axis = 1)               # with the value of the filling front transverse axis = 1 filled vertical axis = 0 filled 
df.fillna (Method = ' backfill ' , axis = 1)            # filled with the value of the back

 

Guess you like

Origin www.cnblogs.com/wen-kang/p/10989919.html