我正在使用spark-df-profiling包在azure databricks中生成分析报告。但是 ProfileReport 中的 to_file
函数会生成一个 html 文件,我无法在 azure blob 上写入该文件。
已经尝试过:
- 包含容器和存储帐户名称的 wasb 路径
- 创建了空的 html 文件,上传到 blob 并使用该 url 进行写入
- 为上面创建的空文件生成 sas token 并给定该 url
profile = spark_df_profiling.ProfileReport(df)
profile.to_file(paths in already tried)
我想将输出保存在提供的此路径上
最佳答案
在查看了julioasotodv/spark-df-profiling
版本v1.1.13
的源代码后,我通过下面的代码解决了这个问题。首先请引用Azure Databricks官方文档Data Sources > Azure Blob Storage
和 Databricks File System
让 dbutils 了解如何将数据写入指定的数据源(例如 Azure 存储)。
这是我的示例代码,它适用于我的 Azure Databricks 和 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 字节输出到 Azure Blob,然后在 Azure 存储资源管理器中检查它。
希望有帮助。
关于python - 如何在azure blob上保存spark-df-profiling生成的html报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57395324/