减去下一行使用当前行,python 数据帧
Subtract next row use current row, python dataframe
我在 python 中有这个 Pandas 数据框,我想知道两行之间的时间差,下一行减去上一行,我应该如何处理这个?
已审核[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
假设您的 Reviewed
列是日期时间,您可以这样做:
df.ix[4, 'Reviewed'] - df.ix[3, 'Reviewed']
如果您想一次对所有行执行此操作:
df['Reviewed'] - df['Reviewed'].shift()
我在 python 中有这个 Pandas 数据框,我想知道两行之间的时间差,下一行减去上一行,我应该如何处理这个?
已审核[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
假设您的 Reviewed
列是日期时间,您可以这样做:
df.ix[4, 'Reviewed'] - df.ix[3, 'Reviewed']
如果您想一次对所有行执行此操作:
df['Reviewed'] - df['Reviewed'].shift()