我在python中有这个Pandas Dataframe,我想知道两行之间的时差,下一行减去前一行,我该如何处理?
已审核[x] - 已审核[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
答案 0 :(得分:5)
假设您的Reviewed
列是日期时间,您可以这样做:
df.ix[4, 'Reviewed'] - df.ix[3, 'Reviewed']
如果您想一次为所有行执行此操作:
df['Reviewed'] - df['Reviewed'].shift()