0

In a dataframe with the structure below:

df = pd.DataFrame({'group_id': [0,0,0,1,1,1],
               'x': [2,3,4,3,4,5],
               'y': [5,6,7,2,2,5],
               'z': [8,8,2,2,6,7]})

How to group data based on group_id values and calculate averages by group_id of columns x, y, z?

Expected output:

group_id | x | y | z
  0      | 3 | 6 | 6
  1      | 4 | 3 | 5
Costa.Gustavo
  • 849
  • 10
  • 21

0 Answers0