pyspark UDF 输出空白
pyspark UDF output blank
我对我的 UDF 函数有疑问:
我有一个数据:raw data
我正在编写代码以将名称列大写:(输入 john doe->putout: John Doe)
@F.udf
def coverCase(Str):
resStr=""
arr=str.split(" ")
for x in arr:
resStr=resStr+ x[0:1].upper()+x[1:len(x)]+" "
return resStr
df.select(coverCase("name")).show()
我没有输出
output screen shot
from pyspark.sql import functions as F
from pyspark.sql.functions import col
df = spark.createDataFrame([(1,"john doe", 21)], ("id", "name", "age"))
@F.udf
def convertCase(str):
resStr=""
arr = str.split(" ")
for x in arr:
resStr= resStr + x[0:1].upper() + x[1:len(x)] + " "
return resStr
df.select(convertCase(col("name"))).show()
+-----------------+
|convertCase(name)|
+-----------------+
| John Doe |
+-----------------+
我对我的 UDF 函数有疑问: 我有一个数据:raw data
我正在编写代码以将名称列大写:(输入 john doe->putout: John Doe)
@F.udf
def coverCase(Str):
resStr=""
arr=str.split(" ")
for x in arr:
resStr=resStr+ x[0:1].upper()+x[1:len(x)]+" "
return resStr
df.select(coverCase("name")).show()
我没有输出 output screen shot
from pyspark.sql import functions as F
from pyspark.sql.functions import col
df = spark.createDataFrame([(1,"john doe", 21)], ("id", "name", "age"))
@F.udf
def convertCase(str):
resStr=""
arr = str.split(" ")
for x in arr:
resStr= resStr + x[0:1].upper() + x[1:len(x)] + " "
return resStr
df.select(convertCase(col("name"))).show()
+-----------------+
|convertCase(name)|
+-----------------+
| John Doe |
+-----------------+