【发布时间】:2019-08-20 08:49:01
【问题描述】:
我在 python(pandas)、databricks 中有以下代码。这工作正常,但它没有过滤掉无效的电话号码。
代码遵循模式并过滤掉家庭和手机号码
import pandas as pd
import re
from pyspark.sql.functions import lit
df = Phonevalidation
# function to check the phone number pattern
def isValid(s):
Pattern = re.compile("(0|44)?[7-9][0-9]{9}")
if(Pattern.match(s)):
return 'Mobile Number'
else: return 'Home phone'
#UDF Register
PhType = udf(isValid)
df1 = Phonevalidation.withColumn('Phtype' ,PhType('Phonenumber') )
display(df1)
我希望过滤掉长度 >10 或
【问题讨论】:
标签: python-2.7