I have a dataframe like the following:
df = pd.DataFrame({'COND1' : [0,4,4,4,0],
'NAME' : ['one', 'one', 'two', 'three', 'three'],
'COND2' : ['a', 'b', 'a', 'a','b'],
'value': [30, 45, 18, 23, 77]})
Where we have two conditions: [0,4]
and ['a','b']
df
COND1 COND2 NAME value
0 0 a one 30
1 4 a one 45
2 4 b one 25
3 4 a two 18
4 4 a three 23
5 4 b three 77
For each name I want to select the a subset with the condition COND1=0 & COND2=a
if I have the information, COND1=4 & COND2=b
otherwise.
the resulting dataframe will be:
df
COND1 COND2 NAME value
0 0 a one 30
1 NaN Nan two NaN
2 4 b three 77
I tried to do the following:
df[ ((df['COND1'] == 0 ) & (df['COND2'] == 'a') |
(df['COND1'] == 4 ) & (df['COND2'] == 'b'))]