python - How to remove rows with specific missing tags from a Pandas dataframe? -


in pandas dataframe, '-999' (as integer) used tag indicate 'cells' missing data. cleaning data removing rows if row contains '-999' in it. tried method:

flag = (dataframe != -999) dataframe = dataframe[flag]  

however, resulting dataframe still has same shape , cells -999 became empty. used line:

dataframe.dropna(axis = 0, how = 'all', inplace = true) 

but did not remove rows expected. can help? thanks!

you can use .any(axis=1) or .all(axis=1) that:

in [92]: df out[92]:         b    c 0    8    7    6 1    8    0 -999 2    8    9    9 3 -999    8    9 4    4    7    6 5    5    9    9 6    6    4    8 7    5 -999    9 8    5    0    5 9    0    6    5  in [93]: df.loc[~(df == -999).any(axis=1)] out[93]:     b  c 0  8  7  6 2  8  9  9 4  4  7  6 5  5  9  9 6  6  4  8 8  5  0  5 9  0  6  5 

or, alternatively, using .all(axis=1):

in [94]: df.loc[(df != -999).all(axis=1)] out[94]:     b  c 0  8  7  6 2  8  9  9 4  4  7  6 5  5  9  9 6  6  4  8 8  5  0  5 9  0  6  5 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -