python panda: return indexes of common rows

后端 未结 2 889
庸人自扰
庸人自扰 2021-01-15 20:01

Apologies, if this is a fairly newbie question. I was trying to find which rows are common between two data frames. The return values should be the row indexes of df2

2条回答
  •  滥情空心
    2021-01-15 20:52

    This can easily be done by merging (inner join) both dataframes:

    common_rows = pd.merge(df1, df2.reset_index(), how='inner', on=['idx_values'])
    

提交回复
热议问题