1

I am trying to index rows of Dataframe with rows not included in the list. For example, here we extract rows 1,2 and 4 of the dataframe (data). But I would like to extract everything but those rows (say rows 3, 5, and 6):

idx = [1,3,4]
subset= data.iloc[idx , :]

So far, I tried this but get the error below:

try = data.iloc[not idx, :]
ValueError: Location based indexing can only have [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array] types
ALollz
  • 54,844
  • 7
  • 56
  • 77
sarah
  • 305
  • 8

1 Answers1

2

Try this:

data.loc[~ data.index.isin(idx)]
I'mahdi
  • 11,310
  • 3
  • 17
  • 23