Python 基于熊猫中的其他间隔标记间隔

Python 基于熊猫中的其他间隔标记间隔,python,pandas,datetime,Python,Pandas,Datetime,我有两个数据帧,a和b b有一个日期时间索引,a有一个Start和End日期时间列 我需要将True标记为b的所有行,这些行的索引位于[开始,结束]距离a 现在我正在做: for _,r in a.iterrows(): b.loc[np.logical_and(b.index>=r.Start, b.index<=r.End),'Label']=True 编辑: 解决方案 不适用于我(他们使用范围来填

我有两个数据帧,
a
b

b
有一个日期时间索引,
a
有一个
Start
End
日期时间列 我需要将
True
标记为
b
的所有行,这些行的索引位于
[开始,结束]
距离
a

现在我正在做:

for _,r in a.iterrows():
    b.loc[np.logical_and(b.index>=r.Start,
                                    b.index<=r.End),'Label']=True
编辑:

解决方案
不适用于我(他们使用范围来填充时间间隔,而我们使用日期时间

这里有一个使用
apply
-

虚拟CSV数据

Date,Start,End
01-08-2019,01-02-2019, 01-10-2019
01-08-2019,01-02-2020, 01-10-2020
代码


这里有一个使用
apply
-

虚拟CSV数据

Date,Start,End
01-08-2019,01-02-2019, 01-10-2019
01-08-2019,01-02-2020, 01-10-2020
代码


像这样做怎么样

def func(): # b.index
    mask = (a['Start'] > date) & (a['End'] <= date)
    df = a.loc[mask]
    if len(df) > 0:
        return True
    else:
        return False

b['Label'] = b.index().to_series().apply(func)
def func():#b.index
掩码=(开始日期)和(结束日期)0:
返回真值
其他:
返回错误
b['Label']=b.index().to_series().apply(func)

像这样做怎么样

def func(): # b.index
    mask = (a['Start'] > date) & (a['End'] <= date)
    df = a.loc[mask]
    if len(df) > 0:
        return True
    else:
        return False

b['Label'] = b.index().to_series().apply(func)
def func():#b.index
掩码=(开始日期)和(结束日期)0:
返回真值
其他:
返回错误
b['Label']=b.index().to_series().apply(func)

我们能得到一个mcve吗?:)谢谢在真实数据中有没有时间的日期时间?我们能得到一个mcve吗?:)谢谢在真实数据中有没有时间的日期时间?
def func(): # b.index
    mask = (a['Start'] > date) & (a['End'] <= date)
    df = a.loc[mask]
    if len(df) > 0:
        return True
    else:
        return False

b['Label'] = b.index().to_series().apply(func)