开始和结束行之间的差异

时间:2015-10-26 17:09:41

标签: python-3.x pandas

我有Pandas DataFrame,想要减去两行,以计算开始和结束事件之间的时间。是否有可能加快此代码:

   frame = dataframe[dataframe['action'] == action]
   rows = []
   beginRow = None
   for index, row in frame.iterrows():
       if row['action_marker'] == 'Start':
           beginRow = row[['datetime', 'ns']]
       elif row['action_marker'] == 'End':
           diffRow = row[['datetime', 'ns']] - beginRow
           diffRow['datetime'] = row['datetime']
           rows.append(diffRow)

表示数据:

datetime    ns    action_marker
16:13:59.559    15600315840824  End 
16:13:59.559    15600315909589  Start
16:13:59.561    15600317346752  End 
16:13:59.561    15600317425992  Start

提前致谢!

0 个答案:

没有答案