Removing missing data

The following R program uses the na.omit() function:

> x<-c(NA,1,2,50,NA) 
> y<-na.omit(x) 
> mean(x) 
[1] NA 
> mean(y) 
[1] 17.66667 

Another R function called na.exclude() could be used as well. The following Python program removes all sp.na code:

import scipy as sp 
x={2,4,3,sp.nan,6,sp.nan,7} 
print(x) 
x.remove(sp.nan) 
print(x)

For brevity, we omitted the output.

Get Hands-On Data Science with Anaconda now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.