I am using pandas in Python.

I have a dataframe:             

col1  col2     col3   col4    col5 col6  col7       Variance    Mean

chr1  1002  NA    NA    2      3          4           .........         .........

chr2   1005  2      3     NA     NA        6          ........        ..........

I want to take row mean and row variance of every row from column no.3 to 7 and also want to ignore NA while calculating mean and variance.The code I m using for mean is

df['means']=df[[3:7]].mean(axis=1)

But it is giving me weird values of mean at some records and NaN for most values.

How to do this?

Am I using the code for selection of columns correctly or not and how to ignore NA during calculation.

More Ahsan Raza's questions See All
Similar questions and discussions