Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Added on July 18, 2023 12:54PM
Likes: 0
Replies: 8
Good day!
I am trying to replace some of the values in one column (empty ones) with values from another column but from previous row. Can't find a solution.
For example: I have columns "A" and "B". What should I do, if I need to replace empty cells A3, A7, A20 etc (where 3, 7, 20 are the numbers of rows from the top) with the values from B2, B6, B19 etc cells?
What would you recommend?
This can be done with a Window recipe. Assuming you have a dataset like this:
Create a Window recipe and set the Window Definition. You need to have a sort order to fetch the previous value so pick the column(s) that has your rows ordered properly:
Then set the aggregation to section to calculate the lag of the row (previous). You can also use the lead (next) if you want:
Run the recipe and you will have the output like this:
Now simply replace the value of A by B in a Prepare recipe using whatever logic you want.
Where is your dataset stored? (which technology). Are you looking for a coders solution (Python recipe) or a clickers solution (Visual recipe)?
Hello, right, sorry. Forgot to mention.
I'm working in a prepare recipe.
Where is your dataset stored? (which technology)
Sorry, It's a Server's Filesystem (in csv format), if that's what you are asking for.
Yes, thanks. I wanted to check if SQL was available as this will be much simpler in SQL.
Good idea! Thank you very much!
Thank you for the solution. It was exactly what I was looking for. It took me a while to find this page though.