小编Rag*_*pta的帖子

PySpark 程序抛出错误“TypeError:无效参数,不是字符串或列”

我有一个名为“new_emp_final_1”的数据框。当我尝试从 CookTime 和 prepTime 派生列“难度”时,通过从 udf 调用函数难度,它给了我错误。

new_emp_final_1.dtypes 如下 -

[('name', 'string'), ('ingredients', 'string'), ('url', 'string'), ('image', 'string'), ('cookTime', 'string'), ('recipeYield', 'string'), ('datePublished', 'strin
g'), ('prepTime', 'string'), ('description', 'string')]
Run Code Online (Sandbox Code Playgroud)

new_emp_final_1.schema 的结果是 -

StructType(List(StructField(name,StringType,true),StructField(ingredients,StringType,true),StructField(url,StringType,true),StructField(image,StringType,true),StructField(cookTime,StringType,true),StructField(recipeYield,StringType,true),StructField(datePublished,StringType,true),StructField(prepTime,StringType,true),StructField(description,StringType,true)))
Run Code Online (Sandbox Code Playgroud)

代码:

def difficulty(cookTime, prepTime):   
    if not cookTime or not prepTime:
        return "Unkown"

    total_duration = cookTime + prepTime
    if total_duration > 3600:
        return "Hard"
    elif total_duration > 1800 and total_duration < 3600:
        return "Medium"
    elif total_duration < 1800:
        return "Easy" 
    else: 
        return "Unkown"

func_udf = udf(difficulty, IntegerType())
new_emp_final_1 …
Run Code Online (Sandbox Code Playgroud)

python apache-spark apache-spark-sql pyspark

4
推荐指数
2
解决办法
3万
查看次数

检查该列是否具有重复自身的单个值

我正在编写一个脚本来识别具有的列值

  1. 具有重复自身的单个值,并且该列中没有其他值。

例如,

00,
111,
2222,
33333,
444444,
5555555,
66666666,
777777777,
8888888888,
99999999999,
00000000000,
9999999999,
88888888,
7777777
Run Code Online (Sandbox Code Playgroud)

任何重复多次且在该列中没有其他数字的值;寻求通用功能或逻辑的帮助以测试相同的功能。

我们可以忽略任何其他值,例如:123 123 123或 1 2 34543 2 1

谢谢。

sql database

1
推荐指数
1
解决办法
43
查看次数

标签 统计

apache-spark ×1

apache-spark-sql ×1

database ×1

pyspark ×1

python ×1

sql ×1