简体   繁体   English

如何查看datetime是否在熊猫中不同数据框的开始时间和结束时间之间

[英]how to see if datetime is between start and end time of different dataframe in pandas

I have following two dataframes in pandas 我在熊猫中有以下两个数据框

   df   
   code    start_time          end_time             start    end     flag
   0      2018-08-01 06:30:00  2018-08-01 06:40:00  123      145     0
   1      2018-08-01 06:40:00  2018-08-01 06:50:00  145      150     0
   2      2018-08-01 07:10:00  2018-08-01 07:20:00  155      160     1

  df1
  code   occur_time           Ack_time               Alarm
  0      2018-08-01 06:50:00  2018-08-01 08:00:00    437           
  1      2018-08-01 06:40:00  2018-08-01 07:10:00    430          
  2      2018-08-01 07:10:00  2018-08-01 07:20:00    456      

The condition I want to check is,in df dataframe flag should be 1 then for that perticular row start_time should be between occur_time and Ack_time and Alarm should be 437 我要检查的条件是,在df dataframe flag应该为1,然后对于该特定行, start_time应该在occur_timeAck_time之间, Alarm应该为437

My desired dataframe would be 我想要的数据框是

  df   
  code    start_time          end_time             start  end   flag  manual
  0      2018-08-01 06:30:00  2018-08-01 06:40:00  123    145   0     1
  1      2018-08-01 06:40:00  2018-08-01 06:50:00  145    150   0     0 
  2      2018-08-01 07:10:00  2018-08-01 07:20:00  155    160   1     0

Try: 尝试:

df.loc[:, 'manual'] = (df1.occur_time.between(df.start_time, df.end_time) \
                       & (df1.Alarm == 437) \
                       & df.flag).apply(int)

EDIT: Added checking the flag also. 编辑:还添加了检查标志。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 pandas dataframe 中的开始时间和结束时间获取时隙 - How to get the timeslots from the start time and end time in the pandas dataframe Pandas即使在不同的行上,如何创建具有开始和结束的新数据帧 - Pandas How to create a new dataframe with a start and end even if on different rows 获取 pandas 中不同时期的开始和结束时间 - Get start and end time for different periods in pandas 使用 Python (pandas, datetime) 在 dataframe 中查找事件(具有开始和结束时间)是否超过特定时间(例如下午 6 点) - Find whether an event (with a start & end time) goes beyond a certain time (e.g. 6pm) in dataframe using Python (pandas, datetime) 如何从 pandas dataframe 事件中创建时间序列,每行都有开始时间和结束时间 - How to create a time series out of a pandas dataframe of events with a start time and end time for each row 重新采样熊猫数据帧并返回开始时间和结束时间 - Resample pandas dataframe and return start time and end time Python,Pandas:如何根据开始时间和结束时间对数据帧的行进行分组 - Python, Pandas: How to club rows rows of dataframe based on Start Time and End Time 如何按组计算熊猫的开始时间和结束时间之间的时差? - How to calculate time difference between start time and end time by group in pandas? 如何在 pandas dataframe 中的日期时间范围之间进行过滤 - How to filter between datetime range in pandas dataframe 在 Pandas dataframe 中,如何根据满足不同条件的起始行和结束行过滤一组行? - In a Pandas dataframe, how to filter a set of rows based on a start row and end row both satisfying different conditions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM