【问题标题】:Saving partitioned parquet on AzureML在 AzureML 上保存分区拼花
【发布时间】:2021-12-11 04:57:38
【问题描述】:

我在一家只允许我们使用 AzureMl 的公司工作。

我们其中一个模型的输出是数据丰富:我们读取包含客户信息的表格,对其进行分段,然后返回带有 customer_idsegment_namesegment_typereference_dtprocessed_dt 的 pandas DataFrame .

我想将此信息保存为 parquet 文件,在 Azure blob 存储中,reference_dt 作为分区。

我在文档中找不到如何执行此操作。我找到的是Dataset.Tabular.register_pandas_dataframe,它将数据存储在不可自定义的路径中,文件夹名称为非人类可读的 UIUD。

每当我们更新该分段时,该方法都会创建另一个版本的数据集,其文件路径位于不同的 UIUD 下。

有没有办法让我控制数据的存储位置,以便我以后可以安全地自动执行此过程?

【问题讨论】:

    标签: azure-storage azureml


    【解决方案1】:

    我终于发现,深埋在 AzureML 文档中,Datastore 资源有一个上传参数,所以我可以完全绕过 Azure ML 的数据集。

    我的解决方案变成了这样:

    # Export to local file system
    temp_file_dir = "dir_path"
    target_path = "target_dir"
    
    # Force PyArrow to create files using the same file name
    # Otherwise, the filename will consist of a different uuid everytime and,
    # not overwritten at the file storage.
    filename_callable = lambda x: "data.parquet"
    
    # To use `partition_filename_cb` the engine must be `pyarrow`
    df.to_parquet(
        temp_file_dir,
        engine="pyarrow",
        partition_cols=["reference_dt"],
        partition_filename_cb=filename_callable,
        index=False,
    )
    # Upload to storage
    datastore = Datastore.get(ws, datastore_name)  # ws is the AzureML workspace
    datastore.upload(
        src_dir=temp_file_dir,
        target_path=target_path,
        overwrite=True,
    )
            
    # Clean temporary files
    shutil.rmtree(temp_file_dir)
    

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 2021-06-26
      • 2021-07-23
      • 2022-07-31
      • 2016-02-12
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多