Pandas:找到给定两个数据帧的前几个相同的时间戳索引

Pandas: find the first couple of timestamp indices that are the same given two dataframes

我有以下 df1:

                      Value
2020-06-02 00:00:00   17
2020-06-03 00:00:00   10
2020-06-05 00:00:00   86

以及以下 df2

                      Value
2020-06-01 00:00:00   16
2020-06-04 00:00:00   9
2020-06-05 00:00:00   86

而且我知道这两个数据帧的长度不同。如何找到 df1.index == df2.index 的第一个和最后两个索引的日期?

在我的示例中,第一对配对的日期是 2020-06-05 00:00:00

使用Index.intersection,然后使用最小值和最大值:

idx = df1.index.intersection(df2.index)
min1 = idx.min()
max1 = idx.max()