我在pyspark中使用自定義函數檢查火花數據框中每行的條件,並在條件爲真時添加列。檢查火花數據框中的行值是否爲空
的代碼如下:
from pyspark.sql.types import *
from pyspark.sql.functions import *
from pyspark.sql import Row
def customFunction(row):
if (row.prod.isNull()):
prod_1 = "new prod"
return (row + Row(prod_1))
else:
prod_1 = row.prod
return (row + Row(prod_1))
sdf = sdf_temp.map(customFunction)
sdf.show()
我得到的錯誤如下提到:
AttributeError的: '統一' 對象有沒有屬性 '的isNull'
我如何檢查爲我自定義函數中當前行中特定列的空值?
你可以'顯示''Dataframe'或至少打印它的模式嗎? –
Dataframe的架構是:根 | - id:string(nullable = true) | - code:string(nullable = true) | - prod_code:string(nullable = true) | - prod:string (nullable = true) – sam