0

in pandas data frame it try to make some statistical analysis on column (heart rate) it aggregate with patient id and hour of measure, then make all statistical analysis

(mean,max,etc)

, my question is how to rename the return result ( to name sum_heart_rate instead of sum, min_heart_rate instead of min ) as follows

newdataframe= df2.groupby(['DayHour','subject_id']).agg({"Heart Rate":['sum' ,'min','max','std', 'count','var','skew']})
mayaaa
  • 289
  • 1
  • 5
  • 14
  • you can also add a `.rename(columns={})` and pass dict values to your col names. also a sample of your dataframe column names would be ideal to help. – Umar.H Oct 04 '19 at 09:11

1 Answers1

0

You can use the below template. You add more columns if needed.

newdataframe= (df2.groupby(['DayHour','subject_id']).agg(sum_heart_rate =('heart rate', 'sum'), min_heart_rate =('heart rate','min'))

For pandas version below 0.25 use code below

newdataframe = df2.groupby('date')['heart rate'].agg([('sum_heart_rate','sum'), ('min_heart_rate','min')])

moys
  • 7,747
  • 2
  • 11
  • 42
  • i think this exactly what i want, but when i try it , it return this error "aggregate() missing 1 required positional argument: 'arg'" @moys – mayaaa Oct 04 '19 at 13:30
  • Please check this https://stackoverflow.com/questions/56821579/pandas-groupby-agg-throws-typeerror-aggregate-missing-1-required-positional if your pandas version is lower than 0.25, you will have to do it a bit differently. – moys Oct 04 '19 at 13:38