【问题标题】:Dask error when compute() is called more that one time多次调用 compute() 时出现 Dask 错误
【发布时间】:2020-06-26 03:25:48
【问题描述】:

我正在使用dask,我需要先使用compute() 执行转换才能继续工作流程。在第二次转换期间似乎对象的类型发生了变化并且正在引发错误'DataFrame' object has no attribute 'compute'

我当前的代码如下:

newtypes = {"age":int, "is_superuser":bool}
df = df.astype(newtypes).compute()
# ....
# 
....
strtypes = {"age":str, "is_superuser":str)
df = df.astype(strtypes).compute() # Here is raised the exception. 

【问题讨论】:

  • 检查type(df)可能是熊猫数据框不支持compute
  • 你是对的,它从<class 'dask.dataframe.core.DataFrame'>变为<class 'pandas.core.frame.DataFrame'>。知道如何解决它吗?我读到了delayed,但由于我需要立即执行转换,这不是我的选择。
  • 这可能会有所帮助,stackoverflow.com/a/39722445/4985099
  • 请首先考虑您要达到的目标,然后重新表述您的问题。

标签: python pandas dataframe dask


【解决方案1】:

如 cmets 中所述,您的第二个数据帧实际上是 Pandas 数据帧,而不是 Dask 数据帧,因此您不需要第二次调用 .compute()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 2018-05-14
    • 2019-07-16
    相关资源
    最近更新 更多