Given the following dataframe -
id value is_mapping
0 1 1 1
1 1 1 1
2 1 1 0
3 2 1 0
4 2 1 0
5 2 1 0
6 3 1 1
7 3 1 1
8 3 1 1
I want to groupby id and sum the values of each id
, and only those when is_mapping == 1
The result should be -
id sum_result
0 1 2
1 2 0
2 3 3
Is there a way to do that without apply?