Outlier removal on a variable with several rows contain NAN (I need to keep the NAN and the position of the NAN also matters)

1394 views python
7

I need to remove outliers from a variable which contains several NANs in it. It looks like this:

 X-velocity

1   0.0345
2   0.0222
3   0.0034
4   0.5604
5   0.4326
6    NaN
7   0.0333
8   0.3635
9   0.3345
10  0.3468
11  0.4573
12  0.7985
13  0.9359
14  NAN
15  0.4635
16  0.6857
17  0.4239
18  NAN
19  0.3849
20  0.3726
21  0.4637
22  0.3647
23  NAN
24  0.2938
25  0.5227

I need to remove the outlier from the variable without delete or change the value or position of the NAN. Is there any possible way to do it? I appreciat any help.

answered question

Depends, what you consider an outlier. Please define it in your question. What would you do if there were no NaN values? You should also provide a Minimal, Complete, and Verifiable example.

1 Answer

2

I'm assuming what you call an outlier is the 'NaN' value (not the "string 'NAN'). If so, have a look at the fillna DataFrame's method.

For instance if you want to replace NaN with 0: df['X-velocity'].fillna(0, inplace=True) will do the job.

posted this

Have an answer?

JD

Please login first before posting an answer.