0

I need help to exclude some rows: I would like for example to exclude three patients from my analysis (patients 1, 2, 6) Can you tell me why this code doesn't work and what I should write?

baseline_all_patients=baseline[baseline["studyid"]!=(1, 2, 6)]
ALollz
  • 57,915
  • 7
  • 66
  • 89

2 Answers2

0

You can try the following:

mask_patient = (~baseline["studyid"].isin([1, 2, 6]))
baseline_all_patients = baseline[mask_patient]
UJIN
  • 1,648
  • 13
  • 28
Kosmos
  • 497
  • 3
  • 11
0

I see 2 issues with the thing you tried:

  1. lists use square brackets
  2. you want the studyids not IN the list, rather than equal to the list.

I think this does what you're trying to do:

import pandas as pd
baseline = pd.DataFrame({'studyid':range(10),'info':range(100,90,-1)})
baseline[~baseline.studyid.isin([1,2,6])]
EMiller
  • 817
  • 1
  • 7
  • 20