0

I have a relatively stupid question which I am not able to formulate very well (and I think it explains why I am not finding any answer)

I would like to calculate the mean, minimum, and maximum of a panda series in my dataframe for many variable (let's say age and weight)

dataframe.age.min()
dataframe.age.max()
dataframe.age.mean()

dataframe.weight.min()
dataframe.weight.max()
dataframe.weight.mean()

I would like to create some kind of loop, which would do something like:

list = ['age','weight']
for x in list: 
    min-"x" = dataframe.x.min()
    max-"x" = dataframe.x.max()
    mean-"x" = dataframe.x.mean()

I would like to have variables called min-age, max-age, mean-age

I don't understand how to define a function, and how to insert in the name min-"x" the name of my variable (x)...

davidism
  • 121,510
  • 29
  • 395
  • 339
salim
  • 321
  • 1
  • 2
  • 12
  • 1
    what are you to do with these variables? it maybe better to just populate a dict with the var string names with the values as your calculated results – EdChum Jun 07 '16 at 14:45
  • I would like to print them in a very big output table... – salim Jun 07 '16 at 14:51
  • 1
    [You don't want to do that.](http://stupidpythonideas.blogspot.cl/2013/05/why-you-dont-want-to-dynamically-create.html) – Zero Piraeus Jun 07 '16 at 14:59

1 Answers1

0

Use describe on you dataframe then manipulate the index.

dfd = df.describe().stack()

dfd.index = dfd.index.to_series().str.join('-')

count-age       10.000000
count-weight    10.000000
mean-age        -0.200662
mean-weight      0.298352
std-age          1.175323
std-weight       0.901915
min-age         -1.778043
min-weight      -0.860798
25%-age         -1.144173
25%-weight      -0.488076
50%-age         -0.092748
50%-weight       0.294160
75%-age          0.276348
75%-weight       0.892405
max-age          1.670823
max-weight       1.680473
dtype: float64
piRSquared
  • 285,575
  • 57
  • 475
  • 624