I would like to calculate the maximum value in a group, but not using the row's own value.
So if we have a data frame like this:
d = {'col1': ["a", "a", "b", "a", "b", "a"], 'col2': [0, 4, 3, -5, -1, 2]}
df = pd.DataFrame(data=d)
print(df)
col1 col2
0 a 0
1 a 4
2 b 3
3 a -5
4 b -1
5 a 2
Then I would like to add a column max_other
like this:
col1 col2 max_other
0 a 0 4
1 a 4 2
2 b 3 -1
3 a -5 4
4 b -1 3
5 a 2 4
Source: This is a follow-up question from this question where I asked about calculating means in groups leaving out the row's own value.
Edit: My max_other
had a mistake in row 1 (it said 3 when it should be 2).