【问题标题】:PySpark NoneType in data despite filtering尽管过滤,PySpark NoneType 在数据中
【发布时间】:2022-01-06 05:51:48
【问题描述】:

我是第一次使用 PySpark,我快疯了。尽管有过滤器功能,但似乎没有从我的 df 中过滤出 None 值。

from nltk.stem.porter import PorterStemmer
from pyspark.sql.functions import col

stemmer = PorterStemmer()

articles = articles.rdd \
.map(lambda r: (" ".join(stemmer.stem(r["content"])),)) \
.toDF(["content"]) \
.where(col("content").isNotNull())

print(articles.count())

这是我得到的错误:
org.apache.spark.SparkException:
作业因阶段失败而中止:
阶段 359.0 中的任务 2 失败 1 次,最近一次失败:在阶段 359.0 中丢失任务 2.0 org.apache.spark.api.python.PythonException:
'AttributeError: 'NoneType' object has no attribute 'lower' ', 从 ,第 11 行。
完整的追溯如下:...

我怀疑地图或 lambda 函数是罪魁祸首,因为如果我将其更改为

lambda r: ('stemmer.stem(r["content"])',).

然后它突然起作用了。

您认为是什么导致了我的问题? 还是应该尝试其他方法来映射列?

【问题讨论】:

    标签: python dataframe apache-spark pyspark rdd


    【解决方案1】:

    异常可能来自PorterStemmer.stem()(https://github.com/nltk/nltk/blob/develop/nltk/stem/porter.py#L658)。 您可以在应用地图之前过滤r["content"] == None

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2017-03-16
      • 2021-04-10
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多