【问题标题】:How to save html report generated by spark-df-profiling on azure blob?如何在 azure blob 上保存 spark-df-profiling 生成的 html 报告?
【发布时间】:2019-12-15 03:29:20
【问题描述】:

我正在使用 spark-df-profiling 包在 azure databricks 中生成分析报告。但是 ProfileReport 中的to_file 函数会生成一个我无法在 azure blob 上编写的 html 文件。

已经试过了:

  1. 带有容器和存储帐户名称的 wasb 路径
  2. 创建空 html 文件,上传到 blob 并使用该 url 编写
  3. 为上面创建的空文件生成 sas 令牌并给出该 url
profile = spark_df_profiling.ProfileReport(df)
profile.to_file(paths in already tried)

我想将输出保存在提供的这个路径上

【问题讨论】:

    标签: python pyspark profiling azure-blob-storage


    【解决方案1】:

    查看julioasotodv/spark-df-profiling的版本v1.1.13的源代码后,通过下面的代码解决了。首先,请参考Azure Databricks官方文档Data Sources > Azure Blob Storage和Databricks File Systemdbutils了解如何将数据写入Azure Storage等指定数据源。

    这是我的示例代码,它适用于 Azure Databricks 和 Azure Storage。

    storage_account_name='<your storage account name>'
    storage_account_access_key='<your storage account key>'
    spark.conf.set(
      "fs.azure.account.key."+storage_account_name+".blob.core.windows.net",
      storage_account_access_key)
    
    # My sample pandas dataframe for testing
    import pandas as pd
    d = {'col1': [1, 2], 'col2': [3, 4]}
    pd_df = pd.DataFrame(data=d)
    
    import spark_df_profiling
    from spark_df_profiling.templates import template
    df = spark.createDataFrame(pd_df)
    profile = spark_df_profiling.ProfileReport(df)
    dbutils.fs.put("wasbs://<your container name>@ppas.blob.core.windows.net/test.html", template('wrapper').render(content=profile.html))
    

    我可以通过结果 True 看到它可以工作,并将 29806 字节输出到 Azure Blob,然后在 Azure 存储资源管理器中进行检查。

    希望对你有帮助。

    【讨论】:

    • 非常感谢您的帮助。它工作正常。'从 spark_df_profiling.templates 导入模板'让事情变得很容易
    猜你喜欢
    • 2021-08-22
    • 2016-08-31
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    相关资源
    最近更新 更多