azure - 使用 azure databricks 将数据帧写入 blob
问题描述
是否有任何链接或示例代码,我们可以使用 python(不使用 pyspark 模块)将数据帧写入 azure blob 存储。
解决方案
下面是用于将(数据帧)CSV 数据直接写入 Azure Databricks Notebook 中的 Azure Blob 存储容器的代码片段。
# Configure blob storage account access key globally
spark.conf.set(
"fs.azure.account.key.%s.blob.core.windows.net" % storage_name,
sas_key)
output_container_path = "wasbs://%s@%s.blob.core.windows.net" % (output_container_name, storage_name)
output_blob_folder = "%s/wrangled_data_folder" % output_container_path
# write the dataframe as a single file to blob storage
(dataframe
.coalesce(1)
.write
.mode("overwrite")
.option("header", "true")
.format("com.databricks.spark.csv")
.save(output_blob_folder))
# Get the name of the wrangled-data CSV file that was just saved to Azure blob storage (it starts with 'part-')
files = dbutils.fs.ls(output_blob_folder)
output_file = [x for x in files if x.name.startswith("part-")]
# Move the wrangled-data CSV file from a sub-folder (wrangled_data_folder) to the root of the blob container
# While simultaneously changing the file name
dbutils.fs.mv(output_file[0].path, "%s/predict-transform-output.csv" % output_container_path)
示例:笔记本
输出:使用 Azure Databricks 写入 Blob 存储的数据帧
推荐阅读
- google-sheets - Google 表格中 =IMPORTXML 的公式解析错误
- python - 为 Python API 速率限制器编写单元测试(TDD 方法)
- python - Python中存储过程绑定中的输出参数
- c - 断开节点并将它们链接到另一个链表的功能?
- unit-testing - K8s 测试:在方案中没有为 v1alpha1.JivaVolume 类型注册类型
- c# - 如何在本地 IdentityContext 中注册从外部身份验证提供程序获得的用户
- typescript - 为什么添加 `& string` 会修复/提高 `keyof` 的智能感知?
- xcode - 找不到适用于 Mac 的有效 SDK
- python - 加载 keras 模型后,batchnorm 层(beta,gamma)不存在梯度
- excel - 如果列中的行范围与另一张表中的列范围匹配,VBA 清除行中单元格的内容