0

For Example im having a data frame

col1   col2   col3

a      12      34

b      23      67

c      67      86

im having list

list=['b','f','r']

i need to remove the rows in the data frame which was there in the list

harvpan
  • 8,571
  • 2
  • 18
  • 36

2 Answers2

1

You need series.isin:

df[~df["col1"].isin(lst)]

P.S. Please, avoid calling variables with python reserved words like list.

koPytok
  • 3,453
  • 1
  • 14
  • 29
0

Setup:

l = ['b','f','r']

df = pd.DataFrame(
         {'col1': {0: 'a', 1: 'b', 2: 'c'},
          'col2': {0: 12, 1: 23, 2: 67},
          'col3': {0: 34, 1: 67, 2: 86}
            })

Now use the .isin method and negate it with a ~

df[~df.col1.isin(l)]

Out:

  col1  col2  col3
0    a    12    34
2    c    67    86
cfort
  • 2,655
  • 1
  • 19
  • 29