0

I have a dataframe like the following

df
      A  B  val
0     0  0   6
1     0  1   6
2     0  2   6
3     0  3   6
4     1  4   7
5     1  5   7
6     1  6   7

I would like to groupby by A and where new_val corresponds to the mean of val (i.e. 6/4=1.5) in this way

df1
     B   newval
0    0    1.5
1    1    1.5
2    2    1.5
3    3    1.5
4    4    2.3
5    5    2.3
6    6    2.3
emax
  • 5,795
  • 11
  • 55
  • 115

0 Answers0