I’m trying to use update to change values in cells like in the tables below. I want consecutive duplicates of a set of columns to be replaced with nulls. Is there a way to do this other than what I’m trying below? There is an issue with the update operation’s where function in which just a single column from update’s parameters is in scope for the row condition for evaluation of the condition. The it variable has the value for a single column from update’s parameters at a time. Additionally, using the column accessor variable as in the example below doesn’t get the value for the columns in the where block as I would like.
val col1 by column<String>() val col2 by column<String>() dataframe .update("col2") .where { col1 == prev()?.get("col1") && col2 == prev()?.get("col2") } .with { null } .update("col1") .where { col1 == prev()?.get("col1") } .with { null }
Base data
col1 | col2 | col3 |
---|---|---|
abc | 1234 | X |
abc | 1234 | Y |
abc | 5678 | X |
abc | 5678 | Y |
def | 1234 | X |
def | 1234 | Y |
def | 1234 | Z |
Target data
col1 | col2 | col3 |
---|---|---|
abc | 1234 | X |
null | null | Y |
*null | 5678 | X |
null | 9012 | X |
def | 1234 | X |
null | null | Y |
null | null | Z |
I tried using it in the where function but it references a single column value in the update operation’s parameters within the scope of where. The column accessor variables don’t get the value of the columns as I validated from results of another update operation. It would be helpful if values for multiple columns in a row can be used in the row condition within where as this would help to perform my udpate requirement.
user25731791 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.