栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

计算间隔中的寄存器数

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

计算间隔中的寄存器数

这里的想法是将所有寄存器打开时间标记为+1,并将所有寄存器关闭时间标记为-1。然后按时间排序,并在+/- 1值上执行累加总和,以在给定时间打开计数。

# initialize interval start times as 1, end times as -1start_times= df.assign(time=df['time'] - pd.Timedelta(hours=2), count=1)all_times = start_times.append(df.assign(count=-1), ignore_index=True)# sort by time and perform a cumulative sum get the count of overlaps at a given time# (subtract 1 since you don't want to include the current value in the overlap)all_times = all_times.sort_values(by='time')all_times['count'] = all_times['count'].cumsum() - 1# reassign to the original dataframe, keeping only the original timesdf['count'] = all_times['count']

结果输出:

      time  count0 2013-01-01 12:56:00      11 2013-01-01 12:00:12      12 2013-01-01 10:34:28      23 2013-01-01 09:34:54      14 2013-01-01 08:34:55      05 2013-01-01 16:35:19      06 2013-01-01 16:35:30      1


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/634553.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号