在Python/Pandas/Excel中为每个ID查找2个不同表的重叠日期 [英] Find overlapping dates of 2 different tables for each ID In Python / Pandas /Excel
本文介绍了在Python/Pandas/Excel中为每个ID查找2个不同表的重叠日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
2个表的每个ID都有多个日期范围,ID总数约为40k.
The 2 tables have multiple date ranges for each ID, the total number of ID around 40k.
期望每个表中的每个ID日期范围都不会重叠,但是两个表之间会发生重叠:在此示例中,有2个不同的ID,表1和表2之间的日期范围之间存在n个重叠.因此我需要在整个数据框中查找表1中的记录与表2中每个ID的日期重叠.
Its expected that each ID date range in each table don't overlap, but the overlap happens between the two tables: In this example of 2 different ID's, there is n overlap between the date ranges between table 1 and table 2, so I need to find across the whole dataframe, which records in table 1 overlaps with dates in table 2 for each ID.
表1
表2
推荐答案
import numpy as np
import pandas as pd
T1 = pd.read_excel('Table1.xslx')
T2 = pd.read_excel('Table2.xslx')
df = pd.merge(T1, T2, how='inner')
print(df)
合并2个数据框会在它们之间产生交集.
Merging of 2 dataframes gives intersection between them.
这篇关于在Python/Pandas/Excel中为每个ID查找2个不同表的重叠日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文