【发布时间】:2019-10-26 21:28:14
【问题描述】:
我有 2 个这样的数据框:
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;
【问题讨论】:
标签: python pandas dataframe filter