For filtering by multiple conditions chain them by &
and filter by boolean indexing
:
q1_fisher_r[(q1_fisher_r['TP53']==1) & q1_fisher_r['TumorST'].str.contains(':1:')]
^^^^ ^^^^
first condition second condition
Problem is this code returned filtered data, so cannot chain by condition:
q1_fisher_r[(q1_fisher_r['TumorST'].str.contains(':1:'))]
Similar problem:
q1_fisher_r[(q1_fisher_r['TP53']==1)]
Sample:
q1_fisher_r = pd.DataFrame({'TP53':[1,1,2,1], 'TumorST':['5:1:','9:1:','5:1:','6:1']})
print (q1_fisher_r)
TP53 TumorST
0 1 5:1:
1 1 9:1:
2 2 5:1:
3 1 6:1
df = q1_fisher_r[(q1_fisher_r['TP53']==1) & q1_fisher_r['TumorST'].str.contains(':1:')]
print (df)
TP53 TumorST
0 1 5:1:
1 1 9:1: