Spark - TypeError:'str'和'int'的实例之间不支持'<='

Posted

技术标签:

【中文标题】Spark - TypeError:\'str\'和\'int\'的实例之间不支持\'<=\'【英文标题】:Spark - TypeError: '<=' not supported between instances of 'str' and 'int'Spark - TypeError:'str'和'int'的实例之间不支持'<=' 【发布时间】:2021-12-10 23:26:58 【问题描述】:

我正在尝试执行以下代码:

df2.groupBy(df2.item_type,df2.product_id)\
    .count()\
    .where(f.col('row' =<3))\
    .withColumn('row',f.row_number().over(\
    Window.partitionBy("item_type")\
    .orderBy(f.col('count')))).show() 

但是我遇到了这个错误:TypeError: '

【问题讨论】:

这里出了点问题,.where(f.col('row' =&lt;3)) 【参考方案1】:

where 子句中的语法错误

...
.where(f.col('row') <= 3)
...

我无法添加评论。 将row 替换为您需要过滤的column name 的名称。

f.col('row') 应替换为f.col('column_name_you_want_to_filter')。例如:f.col('product_id')

【讨论】:

如果我像这样执行,我有以下错误:“pyspark.sql.utils.AnalysisException:”无法解析'row'给定输入列:[item_type,product_id,现在问题出在哪里? :( 什么意思? row 是列的名称。我不明白..你能回复代码吗? 我要过滤的列是“行”。我想我必须将列行字符串转换为int【参考方案2】:

我认为 'row' 是一个字符串

【讨论】:

以上是关于Spark - TypeError:'str'和'int'的实例之间不支持'<='的主要内容,如果未能解决你的问题,请参考以下文章