pandas - Filter out rows with more than certain number of Nan -
In pandora dataframe, I would like to filter all the rows which have more than 2 nanows, basically i have 4 columns And I would like to put those rows, where at least 2 columns have limited value.
The following should be done < < p>
See what we are doing here, Example: Edit This works for the above example but you should be aware that you have a number of columns Set the value to the value and set the value to NaN rows, where the line contains 2 or more non
NaN values.
In
[25]: Import Pandas pd df = pd.DataFrame ({'a': [1,2, NaN, 4,5], 'B': [NaN, 2, NaN, 4,5], 'c': [1,2], nan, nan, nan], 'd': [1,2,3, nan, 5]}) DF Out [25]: ABCD 0 1NN 1 1 2 2 2 2 2 Na Nn N 3 3 4 4 NaN NaN 4 5 5 NaN 5 [5 Rows x 4 Column] [26]: df.dropna (thresh = 2) Out [26]: ABCD 0 1NAN 1 1 2 2 2 2 2 3 4 4 Nain Nain 4 5 5 nan 5 [4 rows x 4 column]
thresh , I thought that basically it means the number of values
NaN but it is actually the Maya Non
NaN value number.
Comments
Post a Comment