Issue
How can I compute the percent change of a column in a vaex dataframe when using the shift
function?
import numpy as np
import vaex
df = vaex.from_arrays(x=np.arange(1,4))
df.x / df.shift(periods=1) - 1
results in an error:
File "<unknown>", line 3
1 1
^
SyntaxError: invalid syntax
Solution
You need to make a copy of the x column and then shift it.
import numpy as np
import vaex
df = vaex.from_arrays(x=np.arange(1,4))
df['x_shifted'] = df.x
df = df.shift(periods=1,column='x_shifted')
df.x/df.x_shifted-1
Answered By - DougR
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.