Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

filter one dataframe by another

df1 = pd.DataFrame({'c': ['A', 'A', 'B', 'C', 'C'],
                    'k': [1, 2, 2, 2, 2],
                    'l': ['a', 'b', 'a', 'a', 'd']})
df2 = pd.DataFrame({'c': ['A', 'C'],
                    'l': ['b', 'a']})
keys = list(df2.columns.values)
i1 = df1.set_index(keys).index
i2 = df2.set_index(keys).index
df1[~i1.isin(i2)]
Comment

PREVIOUS NEXT
Code Example
Python :: dataclass default list 
Python :: python order by date 
Python :: clean column names pandas 
Python :: sklearn support vector machine 
Python :: append dictionary to list python 
Python :: one line if statement without else 
Python :: column type pandas as numpy array 
Python :: how to write in a text file python 
Python :: pandas calculate same day 3 months ago dateoffset 
Python :: pandas earliest date in column 
Python :: create virtual environments python 
Python :: grouped bar chart matplotlib 
Python :: poetry python download windows 
Python :: python 
Python :: if list item in string python 
Python :: remove character(s)from each column in dataframe 
Python :: replace empty numbers in dataframe 
Python :: suppress python vs try/except 
Python :: pyspark print a column 
Python :: userregisterform 
Python :: python sort array by value 
Python :: how to install python libraries using pip 
Python :: create empty numpy array without shape 
Python :: python sns lable axes 
Python :: check regex in python 
Python :: python dequeu 
Python :: how to setup django ionos hostig 
Python :: python pow 
Python :: sqlalchemy one to many 
Python :: python while false loop 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =