I have a simple dataframe:
df = pd.DataFrame({'ID': [100, 101, 134, 139, 192],
'Name': ['Tom', 'Dave', 'Steve', 'Bob', 'Jim']})
and a list of values:
id_list = [100, 139]
I want to drop the rows from my dataframe if the 'ID' column == one of the values in my id_list.
The desired output is...
ID Name
1 101 Dave
2 134 Steve
4 192 Jim
You can use .isin() for the ID series preceded with ~. Essentialy this works like "Not in":
output_df = df[~df['ID'].isin(id_list)]
Output:
ID Name
1 101 Dave
2 134 Steve
4 192 Jim
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With