python - pyspark udf rlike condition in if error -




i using spark 2.1 scripting pyspark scripting

my dataframe given below

dataframe name:df

a

naveen

naveen123

now output should

a

naveen

i using below udf this

def fn(a):     if((a==rlike("[0-9]"))|(a==' ')):         return s  df.withcolumn("flg",fn("a")).show() 

i getting error :global name 'rlike' not defined

please me in crossing hurdle

you want filter not withcolumn adds column.

if want strictly alphabetical :

import pyspark.sql.functions psf df = df.withcolumn("ischarstring", df.a.rlike("^[a-za-z]+$")) 

if want keep strings don't have numbers

df = df.withcolumn("ischarstring", ~df.a.rlike("[0-9]")) 

the error you're getting using function because use rlikeas standalone function not, attribute class pyspark columns. rewrite function in spark:

df = df.withcolumn("ischarstring", psf.when(         df.a.rlike("[0-9]")| (df.a == " "),          psf.lit("s")).otherwise(df.a)) 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -