My dataframes:
df_1 =
userId itemId rating
a i1 0
b i2 1
b i3 0
b i4 1
c i4 1
df_2 =
itemId info1 info2
i1 30 0
i2 20 1
i3 20 0
I want to eliminate the rows in the first dataframe that contain itemId
s which don't appear in the second dataframe, so in this case, i4
doesn't appear so my new dataframe would be:
userId itemId rating
a i1 0
b i2 1
b i3 0
What I tried: I merged the two and then deleted the columns info1
and info2
. I find it unsafe because my dataframes are huge and the same itemId
appears several times in df_1
. Is there a better way to do it?