【问题标题】:azuremlsdk R: How to convert dataset into R dataframe?azuremlsdk R:如何将数据集转换为 R 数据框?
【发布时间】:2020-05-21 14:56:03
【问题描述】:

对于 AzureML Python SDK,我们可以使用返回数据集的 get_by_name()。

import azuremlsdk
mydata = get_by_name(myworkspace, 'mydata')

我可以通过 .to_pandas_dataframe() 方法获取 mydata 的 panda 数据帧

mydata.to_pandas_dataframe()

对于 R 等效项,我被困在这里

mydata <- azuremlsdk::get_dataset_by_name(myworkspace, 'mydata')

问题是,R 有哪些选项可以让我获得表格,例如 csv 或 tibble?

我注意到 R 的 AzureML SDK 的文档记录不如 Python,这使得迁移到 AzureML 对我们的 R 代码库非常具有挑战性。

【问题讨论】:

    标签: r azure azureml


    【解决方案1】:

    Azure 机器学习数据集允许您将数据集中的所有记录加载到数据框中,然后将当前数据集转换为包含 CSV 文件或 Parquet 文件的 FileDataset。

    load_dataset_into_data_frame() => 将数据集中的所有记录加载到数据框中。

    convert_to_dataset_with_csv_files() => 将当前数据集转换为包含 CSV 文件的 FileDataset。

    convert_to_dataset_with_parquet_files() => 将当前数据集转换为包含 Parquet 文件的 FileDataset。

    示例:将数据转换为数据框。

    #' Load all records from the dataset into a dataframe.
    #'
    #' @description
    #' Load all records from the dataset into a dataframe.
    #'
    #' @param dataset The Tabular Dataset object.
    #' @return A dataframe.
    #' @export
    #' @md
    load_dataset_into_data_frame <- function(dataset)   {
      dataset$to_pandas_data_frame()
    }
    
    #' Convert the current dataset into a FileDataset containing CSV files.
    #'
    #' @description
    #' Convert the current dataset into a FileDataset containing CSV files.
    #'
    #' @param dataset The Tabular Dataset object.
    #' @param separator The separator to use to separate values in the resulting file.
    #' @return A new FileDataset object with a set of CSV files containing the data
    #' in this dataset.
    #' @export
    #' @md
    
    convert_to_dataset_with_csv_files <- function(dataset, separator = ",") {
      dataset$to_csv_files(separator)
    }
    
    #' Convert the current dataset into a FileDataset containing Parquet files.
    #'
    #' @description
    #' Convert the current dataset into a FileDataset containing Parquet files.
    #' The resulting dataset will contain one or more Parquet files, each corresponding
    #' to a partition of data from the current dataset. These files are not materialized
    #' until they are downloaded or read from.
    #'
    #' @param dataset The Tabular Dataset object.
    #' @return A new FileDataset object with a set of Parquet files containing the
    #' data in this dataset.
    #' @export
    #' @md
    convert_to_dataset_with_parquet_files <- function(dataset) {
      dataset$to_parquet_files()
    }
    

    参考:Azuremlsdk - working with datasets

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      • 2015-01-05
      • 1970-01-01
      • 1970-01-01
      • 2022-06-10
      • 1970-01-01
      相关资源
      最近更新 更多