Divide current row with previous row in Dataiku
Hi I have a question. How does one divide the current row with previous row in Dataiku? For example, let's say I have a column that contains stock prices, and I would like to calculate the change in price by dividing current row with previous row and minusing 1. How does one do that?
Best Answer
-
Here was how I solved it: I used the "Window" recipe. First, I partitioned by the correct column at which to perform subset operations on. Next, I order column by datetime (if there is one). Finally, I selected "Lag" for the column Price under Aggregations to get the lag. Next, using a "Prepared" recipe and "formula", I divided the current Price column with the newly created "Lag" column to get the change in price as wanted.
Answers
-
tgb417 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 1,598 Neuron
Take a look at the window visual recipie.
Training materials that might be helpful can be found here.
https://academy.dataiku.com/data-pipelines/513267
Hope that helps
The idea is that you would order by some value like a trading day. You might group by some other value like a specific stock. Then you would want the lag value from the earlier day's trading. In a separate step, you would then do your arithmetic to get your percent change. Or you might do this in a custom agrigation.
Hope this helps.
-
Thank you for your answer. I did manage to solve it