我正在尝试在数据框中创建一个新列,其中包含与日期/时间所属的间隔相关的值。
需要更改间隔以允许对数据进行不同的分析
数据帧的示例如下,但原始文件大约是50k行(并且有许多文件要以这种方式处理):
Coaster1 Coaster2 Coaster3 Epoch
nDateTime
2015-09-22 12:32:10 0 1 0 1.442925e+09
2015-09-22 12:32:11 0 1 0 1.442925e+09
2015-09-22 12:32:11 0 1 0 1.442925e+09
2015-09-22 12:32:12 0 1 0 1.442925e+09
2015-09-22 12:32:12 0 1 0 1.442925e+09
2015-09-22 12:32:13 0 1 0 1.442925e+09
2015-09-22 12:32:13 0 1 0 1.442925e+09
2015-09-22 12:32:14 0 1 0 1.442925e+09
2015-09-22 12:32:14 0 1 0 1.442925e+09
2015-09-22 12:32:15 0 1 0 1.442925e+09
2015-09-22 12:32:15 0 1 0 1.442925e+09
2015-09-22 12:32:16 0 1 0 1.442925e+09
2015-09-22 12:32:17 0 1 0 1.442925e+09
2015-09-22 12:32:17 0 1 0 1.442925e+09
2015-09-22 12:32:17 0 1 0 1.442925e+09
所需的输出将包括新的列“块”,由索引(nDateTime)或Epoch时间戳以5秒的间隔(对于此示例)计算。 Epoch已按升序对数据进行了排序,但有许多情况下样本数量不固定,因此无法确定固定的“行块”大小。
是否有pythonic&大熊猫适合这样做的方法吗?
示例所需输出:
Coaster1 Coaster2 Coaster3 Epoch block
nDateTime
2015-09-22 12:32:10 0 1 0 1.442925e+09 1
2015-09-22 12:32:11 0 1 0 1.442925e+09 1
2015-09-22 12:32:11 0 1 0 1.442925e+09 1
2015-09-22 12:32:12 0 1 0 1.442925e+09 1
2015-09-22 12:32:12 0 1 0 1.442925e+09 1
2015-09-22 12:32:13 0 1 0 1.442925e+09 1
2015-09-22 12:32:13 0 1 0 1.442925e+09 1
2015-09-22 12:32:14 0 1 0 1.442925e+09 1
2015-09-22 12:32:14 0 1 0 1.442925e+09 1
2015-09-22 12:32:15 0 1 0 1.442925e+09 1
2015-09-22 12:32:15 0 1 0 1.442925e+09 1
2015-09-22 12:32:16 0 1 0 1.442925e+09 2
2015-09-22 12:32:17 0 1 0 1.442925e+09 2
2015-09-22 12:32:17 0 1 0 1.442925e+09 2
2015-09-22 12:32:17 0 1 0 1.442925e+09 2
感谢您查看此内容和您的帮助!