I want to filter df1 based on a column of df2. I would only need to keep the rows in df1 if they appear in df2. I tried using isin()
like so:
df1 = pd.DataFrame({'A' : [5,6,3,6,3,4]})
df2 = pd.DataFrame({'B' : [0,0,3,6,0,0]})
df1[df1['A'].isin(df2['B'])]
Which gives the desired df:
A
6
3
6
3
However, my dataframes are very large (millions of rows) so this operation takes a significant amount of time. Are there other, more efficient ways to get the desired result?