#NEWLINE# @ staticmethod #NEWLINE# def replace_value( field , original , replacement ) : #NEWLINE# #INDENT# if ( original is not None ) : #NEWLINE# #INDENT# transformation = pmml . Apply ( function = 'if' ) #NEWLINE# cond = pmml . Apply ( function = 'equals' ) #NEWLINE# cond . append ( pmml . FieldRef ( field = field ) ) #NEWLINE# cond . append ( pmml . Constant ( original ) ) #NEWLINE# transformation . append ( pmml . Constant ( field ) ) #NEWLINE# transformation . append ( pmml . FieldRef ( field = field ) ) #NEWLINE# return { #NEWLINE# #INDENT# DerivedFeatureTransformations . TRANSFORMATION : transformation , #NEWLINE# DerivedFeatureTransformations . FUNCTION : ( lambda df : np . where ( ( df [ field ] == original ) , replacement , df [ field ] ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# transformation = pmml . Apply ( function = '+' , mapMissingTo = replacement ) #NEWLINE# transformation . append ( pmml . Constant ( 0 ) ) #NEWLINE# transformation . append ( pmml . FieldRef ( field = field ) ) #NEWLINE# return { #NEWLINE# #INDENT# DerivedFeatureTransformations . TRANSFORMATION : transformation , #NEWLINE# DerivedFeatureTransformations . FUNCTION : ( lambda df : np . where ( df [ field ] . isnull ( ) , replacement , df [ field ] ) ) , #NEWLINE# #UNINDENT# }