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
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
You need series.isin
:
df[~df["col1"].isin(lst)]
P.S. Please, avoid calling variables with python reserved words like list
.
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