1

I have an array of data with nan values

enter image description here

I want to remove rows with nan values. I want this output:

enter image description here

Leaving only the rows without the nan values.

I tried to use this code

input = input[~np.isnan(input)]

However, the rows did not remove.

I also used

a = input[complete.cases(input), ]

But an error occurred. NameError: name 'complete' is not defined

1
  • 1
    "complete.cases" is for R Commented Oct 7, 2020 at 2:26

3 Answers 3

1

Dataframe:

   values_1  values_2
0     700.0       NaN
1       NaN     150.0
2     500.0     350.0
3       NaN     400.0
4    1200.0    5000.0

You can try this:

df = df.dropna()
df = df.reset_index(drop=True)

Outputs:

   values_1  values_2
0     500.0     350.0
1    1200.0    5000.0
Sign up to request clarification or add additional context in comments.

3 Comments

Got an erro : AttributeError: 'list' object has no attribute 'dropna'
by the way, I edit the input data, Instead of "Nan" it must be "nan".
what's type of "nan"? string or np.nan
1

Given numpy array as

import numpy as np
input = np.array([[1,1,0,np.nan], [1,1,1,30], [1,0,1,np.nan]])

try

output = input[~np.isnan(input).any(axis=1)]

gives output as

[[ 1.  1.  1. 30.]]

Comments

0

Try this

input = input[~np.isnan(input).any(axis=1)]

any(axis=1) reduces an m*n array to n with an logical or operation on the whole rows.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.