Ready for Dataiku 10? Try out the Crash Course on new features!GET STARTED

How to fill the column with the value in a row based on a condition

Tsurapaneni
Level 3
Level 3
How to fill the column with the value in a row based on a condition

Hi Team,

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 !

 

0 Kudos
2 Replies
AgatheG
Dataiker
Dataiker

Hi Tsurapaneni,

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][0]

 

Hope this helps!

 

Agathe

0 Kudos
Tsurapaneni
Level 3
Level 3
Author

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. 

0 Kudos
A banner prompting to get Dataiku DSS