Python Forum

Full Version: How to calculate variance(standard deviation) by column
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I have below data (DataFrame), and want to calculate variance(standard deviation) by column & and by name

Name    V1    V2    V3   V4
AABB    1.23  1.56  2.6  7.3
ABAB    5.23  3.56  2.6  7.8
AABB    2.23  6.56  4.6  5.8
AABC    2.23  1.56  2.6  5.8
ABAB    5.43  3.66  1.9  6.8
AABC    0.23  7.56  7.1  8.3
AABB    2.23  1.56  2.6  5.8


Desired output(Standard deviation):

Name	V1	    V2	      V3	V4
AABB	0.577 	2.887 	1.155 	0.866 
AABC	1.414 	4.243 	3.182 	1.768 
ABAB	0.141 	0.071 	0.495 	0.707 
DataFrame.var() is only giving me the overall(not by name), I Want by name.
what have you tried so far?
show code
Tried code is below, but it can not give me the output by group

DataFrame.var()
Desired output(Standard deviation):
 
Name    V1      V2        V3    V4
AABB    0.577   2.887   1.155   0.866 
AABC    1.414   4.243   3.182   1.768 
ABAB    0.141   0.071   0.495   0.707