Reputation: 46483
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.
Upvotes: 5
Views: 299
Reputation: 47
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
Upvotes: 1