Make median work properly by forcing dtype for dataframe to be float. add groupby on multiple fields.