【问题标题】:Is there any way to Drop pyspark Dataframe after converting it into pandas Dataframe via toPandas()通过 toPandas() 将 pyspark Dataframe 转换为 pandas Dataframe 后,有什么方法可以删除它
【发布时间】:2019-08-14 05:43:04
【问题描述】:

我使用 pyspark 使用大小为 4GB 的输入文本文件创建 Spark Dataframe。然后使用一些条件,例如:

df.cache() #cache df for fast execution of later instruction
df_pd = df.where(df.column1=='some_value').toPandas() #around 70% of data

现在我正在对 pandas Dataframe df_pd 进行所有操作。现在我的内存使用量大约为 13 GB。

  • 为什么,消耗了这么多内存?
  • 如何才能使我的计算更快更高效? #here df.cache() 导致缓存需要 10 分钟。
  • 我尝试使用 df.unpersist()sqlContext.clearCache() 来释放 pyspark DF 内存,但没有帮助。

注意:我主要使用 Pyspark,因为它有效地使用了 cpu 内核,而 pandas 只使用我机器的单核进行读取文件操作。

【问题讨论】:

标签: pandas apache-spark pyspark


【解决方案1】:

为什么会消耗这么多内存?

正如你所建议的,我会说内存中的数据帧重复。

如何才能让我的计算更快、更高效? #here df.cache() 运行了 10 分钟

df.cache() 仅在您要多次使用此 df 时才有用。将其视为一个检查点,仅当您需要对同一数据帧执行多个操作时才有用。在这里,没有必要,因为您只执行一个过程。 More info here.

我尝试使用 df.unpersist()sqlContext.clearCache() 来释放 pyspark DF 内存,但没有帮助。强>

unpersist 是正确的做法。关于sqlContext.clearCache(),我不知道你使用的是哪个版本的Spark,但你可能想看看spark.catalog.clearCache()

虽然我知道这并不能直接回答您的问题,但希望对您有所帮助!

【讨论】:

    【解决方案2】:

    尝试删除 PySpark df 怎么样? :

    del(df)
    

    【讨论】:

    • 它没有释放内存我首先尝试 del(df) 然后我也尝试了 gc,collect()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 2017-03-23
    • 2018-02-15
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    相关资源
    最近更新 更多