I would like to compute the difference between consecutive data row's timestamps.
Why does this work, as explained here :
df['tvalue'] = df.index
print df['tvalue'].shift() - df['tvalue']
but not
print df.index.shift() - df.index
which produces ValueError: Cannot shift with no freq
?
The problem is that the working solution doubles the memory size needed for timestamp; this is a problem for huge dataframes.
Can't you just input a frequency, either shift(1)
or shift(-1)
print df.index.shift(1) - df.index
print df.index.shift(-1) - df.index
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With