Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
I have a use case where I have to replace a value based on the row value on another condition. for an instance I have 3 columns (ABC) and have to generate a new column (D)
A. B. C. Output ->. A. B. C. D
2 red. red 2. red. red. 2
3. red. blue 3 red blue 2
4 green. pink 4. green pink. 2
In the above example I have created a new column which is D based on the condition that if ((B==C), A, 000) which gives the value 0 for the rest of the rows which aren't a match but I want the same value throughout the column without explicitly defining the value (eg: using the fill column processor and using the 2 to the value). this might serve now but not in future.
Thanks in advance !
I am not sure to understand your use case. From what I gathered in your post, you mean to:
1. Find the value in column A such that B == C (assuming either one and only one row matches this condition, or that A always takes the same value for rows matching the condition)
2. Create a new column D filled with the value computed in step 1
If this is indeed your intent to do, you can do so with a short Python recipe, using these lines:
dataset = dataiku.Dataset(YOUR_DATASET_NAME) df = dataset.get_dataframe() df["D"] = df.A[df.B == df.C]
Hope this helps!
expecting the solution in the prep recipe through formulas but not in the python code recipes. I am good with python but I am looking only through formulas in the prep visual recipe.