如何在azure blob上保存sparkdfprofiling生成的html报告?

2024-04-28 20:27:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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)

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


Tags: 文件to路径urldfhtml报告profile
1条回答
网友
1楼 · 发布于 2024-04-28 20:27:43

在我查看了julioasotodv/spark-df-profiling版本v1.1.13的源代码后,我通过下面的代码解决了它。首先,请参考Azure Databricks官方文档^{}^{}了解dbutils如何将数据写入指定的数据源,如Azure存储。在

这是我的示例代码,它适用于我的Azure数据库和Azure存储。在

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字节输出到azureblob,然后在azurestorageexplorer中检查它。在

enter image description here

enter image description here

希望有帮助。在

相关问题 更多 >