0

Considering the following dataframe, I need the df dataframe to have only id's not in df_inf and df_sup:

import pandas as pd

df = pd.DataFrame({'id':[1,2,3,4,5,6,7,8], 'name':['a','b','c','d','e','f','g','h']})
df_inf = pd.DataFrame({'id': [1,2,3]})
df_sup = pd.DataFrame({'id': [6,7,8]})

Is there any proper function of pandas that operates? I'm trying in a fairly trivial way and it's not giving back:

df = df['id'] - (df_inf['id'] + df_sup['id'])
df
1
  • df[~(df["id"].isin(df_inf["id"]) | df["id"].isin(df_sup["id"]))] Commented Dec 11, 2019 at 14:55

1 Answer 1

2

You can filter id as follows:

df = df[(~df['id'].isin(df_inf['id'])) & (~df['id'].isin(df_sup['id']))]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.