我有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
提前致谢!