I have below df
df = pd.DataFrame({
'Market': {0: 'Zone1',
1: 'Zone1',
2: 'Zone1',
3: 'Zone1',
4: 'Zone2',
5: 'Zone2',
6: 'Zone2',
7: 'Zone2'},
'col1': {0: 'v1',
1: 'v2',
2: 'v3',
3: 'v4',
4: 'v1',
5: 'v2',
6: 'v3',
7: 'v4'},
'col2': {0: np.nan,
1: 1,
2: 6,
3: 2,
4: np.nan,
5: 2,
6: 1,
7: 2,},
'col3': {0: np.nan,
1: 9,
2: 5,
3: 2,
4: np.nan,
5: 0,
6: 9,
7: 1,}})
For Market's each value(i.e Zone1 and Zone2) for nan values associated with value v1 in col1 , I want to replace with sum of values associated with v2 and v4. So that output will look like this -
Market col1 col2 col3
-----------------------------------
0 | Zone1 v1 3 11
1 | Zone1 v2 1 9
2 | Zone1 v3 6 5
3 | Zone1 v4 2 2
4 | Zone2 v1 4 1
5 | Zone2 v2 2 0
6 | Zone2 v3 1 9
7 | Zone2 v4 2 1