【问题标题】:Reading multiple Excel files with Dask使用 Dask 读取多个 Excel 文件
【发布时间】:2021-06-20 12:03:47
【问题描述】:

有人可以帮助我了解如何在 Dask 中读取多个 excel 文件吗? 在 Pandas 中,我会使用 Glob 并执行此操作

files = glob.glob('Working Files/*.xlsx')
df = pd.concat([pd.read_excel(i, skiprows=2) for i in files], ignore_index=True)

在 Dask 中需要帮助

谢谢,

杰克

【问题讨论】:

    标签: python pandas dataframe dask dask-dataframe


    【解决方案1】:

    最简单的解决方案是将您的函数包装在 delayed API 中:

    import dask
    
    files = glob.glob('Working Files/*.xlsx')
    
    # note we are wrapping in delayed only the function, not the arguments
    delayeds = [dask.delayed(pd.read_excel)(i, skiprows=2) for i in files]
    
    # the line below launches actual computations
    results = dask.compute(delayeds)
    
    # after computation is over the results object will 
    # contain a list of pandas dataframes
    df = pd.concat(results, ignore_index=True)
    

    【讨论】:

    • 非常感谢您的快速回复;一个问题:通过执行此 pd.concat 我将从 Dask 迁移到 pandas,对吗?我正在尝试切换到 Dask,因为我读到 Dask 更快,这种方法仍然是最佳方法吗?我可以在 Dask 本身中连接,那不是更快吗? PS:对不起,如果这是一个愚蠢的想法:P,我对这些还很陌生
    • 根据您的用例、数据等,将数据保存在 pandas 中可能会更快...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-07
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    相关资源
    最近更新 更多