find average variance across columns & average of variance across rows in python

Viewed 24

I have the data as follows:-

  a  b   c   d
  5  6   32  12
  9  8   16  23
  15 8   14  20

I want to check the variance of each column and then have 1 variance for each column. Then I would like to get average of variance across columns & finally reach one number for this entire dataset. Can anyone please help?

1 Answers

Do you want var and mean?

df.var().mean()

output: 39.083333333333336

intermediate:

df.var()

a    25.333333
b     1.333333
c    97.333333
d    32.333333
dtype: float64

NB. by default, var used 1 degree of freedom (ddof=1) to compute the variance. Id you want 0, use df.var(ddof=0).

Related