Home > Software design >  drop all rows that contain even one alphabet in pyspark
drop all rows that contain even one alphabet in pyspark

Time:12-24

pyspark 2.3.1

my rows to col1 should only contain integers. I am trying to filter out any row that have even one character. How can I do this in pyspark?

I've tried

df.select('col1').filter(df.col1.rlike(^[a-zA-Z])) 

however rows that contain alphabet also contain integers therefore not filtered.

How can I do this?

CodePudding user response:

You can try to select pure digital rows.

df = df.filter('col1 rlike "^[0-9] $"')
df.show(truncate=False)
  • Related