I have 2 dataframes like this:
df1
sales day ...
index
1001 567 321
1002 600 1530
1005 789 998
1008 825 775
1002 300 1120
df2
sales day ...
index
1001 567 321
1002 600 1530
1005 789 998
1014 620 1000
1008 825 775
1009 589 1100
1002 300 1120
1005 770 400
1008 820 1600
我希望保留df2中索引和日期值与df1完全相同的行。
因此结果应该是:
df2
sales day ...
index
1001 567 321
1002 600 1530
1005 789 998
1008 825 775
1002 300 1120
我无法使用以下isin函数,因为df2中存在具有相同索引但不同日期值的行。唯一的组合是索引和日期。
df2 = df2[df2.index.isin(df1.index)]
本质上我想在SQL中做的是
select *
from table1 t1,
table2 t2,
where t1.id = t2.id
and t1.day = t2.day;