我是新手,对于Spark SQL和DataFrames并不熟悉。我有一个Dataframe,需要基于其他列的值添加一个新的列。我有一个Excel中的嵌套IF公式(用于向新列添加值),转换为编程术语后,大致如下:
if(k =='yes')
{
if(!(i==''))
{
if(diff(max_date, target_date) < 0)
{
if(j == '')
{
"pending" //the value of the column
}
else {
"approved" //the value of the column
}
}
else{
"expired" //the value of the column
}
}
else{
"" //the value should be empty
}
}
else{
"" //the value should be empty
}
j,k是Dataframe中的另外两列。 我知道我们可以使用withColumn
和when
基于其他列添加新的列,但我不确定如何使用这种方法实现上述逻辑。 有什么简单/有效的方法可以实现添加新列的上述逻辑吗? 感谢您的帮助。