Home > OS >  PySpark: How do I count number of spaces between in a string?
PySpark: How do I count number of spaces between in a string?

Time:10-20

I know it is doable in Python, but is there any built-in function or Like or IN like facility? For instance, if the name column contains John Doe then it should return 4 as space count.

Or should I create a UDF?

CodePudding user response:

A couple of options:

F.size(F.split('col_name', ' ')) - 1
F.length(F.regexp_replace('col_name', '[^ ] ', ''))
  • Related