pythonRcpp
pythonRcpp

Reputation: 2146

Apply difference function on each adjacent row value pandas

I have a df like below and want to see if timestamps are always increasing. Basically a diff in each row for timestamp column. Add diff in a third column.

A,B,Timestamp
5,58330831,1491375186654664218
5,58330832,1491375186654673017
5,58330833,1491375186654687270
5,58330834,1491375186654696695
5,58330835,1491375186654712416

Upvotes: 1

Views: 1468

Answers (1)

zipa
zipa

Reputation: 27869

You can do it like this:

df['diff'] = (df['Timestamp'] - df['Timestamp'].shift(1))>0

First one will be False as it has no value to compare and returns NaN.

Upvotes: 1

Related Questions