'how does timedelta64[s] function works in python pandas

below is link to my min dataset values

https://i.stack.imgur.com/PTwlg.png

my timedeltah64[s] function is giving me wrong answers can someone explain to me where im going wrong with it

z =(data.iloc[1,8:9]-data.iloc[2,8:9]).astype('timedelta64[s]')
print(z)

result i'm getting

Time   -177.0
dtype: float64

instead of 3 seconds



Solution 1:[1]

Problems might be that you use iloc with 1 and 2. Since iloc is 0 indexed, you are actually subtracting the second row and the third row.

To get difference of consecutive rows, you can use diff() function

data['Time'].diff().astype('timedelta64[s]')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 9769953