我在 python 中有这个 Pandas Dataframe,我想知道两行之间的时间差,下一行减去前一行,我应该如何处理?
Reviewed[x] - Reviewed[x-1] x 是该行所在的编号
ReporterID ID Type Reviewed
0 27545252 51884791 ReportID 2015-01-14 00:00:42.640000
1 29044639 51884792 ReportID 2015-01-14 00:00:02.767000
2 29044639 51884793 ReportID 2015-01-14 00:00:28.173000
3 29044639 51884794 ReportID 2015-01-14 00:00:46.300000
4 27545252 51884796 ReportID 2015-01-14 00:01:54.293000
5 29044639 51884797 ReportID 2015-01-14 00:01:17.400000
6 29044639 51884798 ReportID 2015-01-14 00:01:57.600000
最佳答案
假设您的 Reviewed
列是您可以执行的日期时间:
df.ix[4, 'Reviewed'] - df.ix[3, 'Reviewed']
如果您想一次对所有行执行此操作:
df['Reviewed'] - df['Reviewed'].shift()
关于python - 减去下一行使用当前行,python 数据帧,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28120122/