How do I return a value based on another column per group in pandas
Guess I could just create a groupby df (groupby group where mth == 2) then merge back to it.
Will just go with that instead of attempting to do via a groupby.apply route!
I have a pandas dataframe such as:




group
month
value




1
1
2


1
2
2


1
3
3


2
1
7


2
2
8


2
3
8


3
1
9


3
2
0


3
3
1




And I want to calculate a new column ('want' in the below) equal to the value where month == 2, per group, as shown below:




group
month
value
want




1
1
2
2


1
2
2
2


1
3
3
2


2
1
7
8


2
2
8
8


2
3
8
8


3
1
9
0


3
2
0
0


3
3
1
0




Anyone able to help?