在 Azure 機器學習 中使用數據表
適用於:Azure CLI ml 延伸模組 v2 (目前)Python SDK azure-ai-ml v2 (目前)
Azure 機器學習 支援資料表類型 (mltable
)。 這可讓您建立 藍圖 ,以定義如何將數據檔載入記憶體作為 Pandas 或 Spark 資料框架。 在本文中,您將了解:
- 何時使用 Azure 機器學習 資料表,而不是檔案或資料夾。
- 如何安裝
mltable
SDK。 - 如何使用檔案定義數據載入藍圖
mltable
。 - 示範如何在
mltable
Azure 機器學習 中使用的範例。 - 如何在互動式開發期間使用
mltable
(例如,在筆記本中)。
必要條件
Azure 訂用帳戶。 如果您還沒有 Azure 訂用帳戶,請在開始前建立免費帳戶。 試用免費或付費版本的 Azure Machine Learning。
Azure Machine Learning 工作區。
重要
請確定您已在 Python 環境中安裝最新的 mltable
套件:
pip install -U mltable azureml-dataprep[pandas]
複製範例存放庫
本文中的程式碼片段是以 Azure Machine Learning 範例 GitHub 存放庫中的範例為基礎。 若要將存放庫複製到您的開發環境,請使用此命令:
git clone --depth 1 https://github.com/Azure/azureml-examples
提示
使用 --depth 1
僅將最新的認可複製到存放庫。 這樣可縮短完成作業所需的時間。
您可以在複製存放庫的下列資料夾中找到與 Azure 機器學習 資料表相關的範例:
cd azureml-examples/sdk/python/using-mltable
簡介
Azure 機器學習 資料表 (mltable
) 可讓您將資料檔載入記憶體的方式定義為 Pandas 和/或 Spark 資料框架。 資料表有兩個主要功能:
- MLTable 檔案。 定義數據載入 藍圖的 YAML 型檔案。 在 MLTable 檔案中,您可以指定:
- 數據的儲存位置 - 本機、雲端或公用 HTTP(s) 伺服器上的記憶體位置。
- 透過雲端記憶體的 Globbing 模式。 這些位置可以指定具有通配符 (
*
) 的檔名集合。 - 讀取轉換 - 例如,檔格式類型(分隔文字、Parquet、Delta、json)、分隔符、標頭等。
- 數據行類型轉換(強制執行架構)。
- 使用資料夾結構資訊建立新資料列 - 例如,使用
{year}/{month}
路徑中的資料夾結構建立年份和月份數據行。 - 要載入的數據子集 - 例如,篩選數據列、保留/卸除數據 行、取得隨機樣本。
- 根據 MLTable 檔案中定義的藍圖,快速且有效率的引擎 將數據載入 Pandas 或 Spark 數據框架。 引擎依賴 Rust 來獲得高速和記憶體效率。
Azure 機器學習 數據表在下列案例中很有用:
- 您必須 在儲存位置上執行 Glob 。
- 您必須使用來自不同記憶體位置的數據來建立數據表(例如,不同的 Blob 容器)。
- 路徑包含您想要在數據中擷取的相關信息(例如日期和時間)。
- 數據架構經常變更。
- 您想要輕鬆 重現 數據載入步驟。
- 您只需要大型數據的子集。
- 您的資料包含您想要串流至 Python 工作階段的儲存位置。 例如,您想要在下列 JSON 行結構中串流
path
:[{"path": "abfss://fs@account.dfs.core.windows.net/my-images/cats/001.jpg", "label":"cat"}]
。 - 您想要使用 Azure 機器學習 AutoML 來定型 ML 模型。
提示
Azure 機器學習 不需要針對表格式數據使用 Azure 機器學習 資料表 (mltable
)。 您可以使用 Azure 機器學習 檔案 (uri_file
) 和資料夾 (uri_folder
) 類型,而您自己的剖析邏輯會將資料載入 Pandas 或 Spark 資料框架。
如果您有簡單的 CSV 檔案或 Parquet 資料夾,則使用 Azure 機器學習 檔案/資料夾,而不是資料表會比較容易。
Azure 機器學習 數據表快速入門
在本快速入門中,您會從 Azure 開放數據集建立 NYC 綠色計程車數據的數據表 ()。mltable
數據具有 parquet 格式,且涵蓋 2008-2021 年。 在可公開存取的 Blob 記憶體帳戶上,數據檔具有下列資料夾結構:
/
└── green
├── puYear=2008
│ ├── puMonth=1
│ │ ├── _committed_2983805876188002631
│ │ └── part-XXX.snappy.parquet
│ ├── ...
│ └── puMonth=12
│ ├── _committed_2983805876188002631
│ └── part-XXX.snappy.parquet
├── ...
└── puYear=2021
├── puMonth=1
│ ├── _committed_2983805876188002631
│ └── part-XXX.snappy.parquet
├── ...
└── puMonth=12
├── _committed_2983805876188002631
└── part-XXX.snappy.parquet
使用此資料,您想要載入 Pandas 資料框架:
- 只有 parquet 檔案 2015-19 年。
- 數據的隨機樣本。
- 只有撕裂距離大於 0 的數據列。
- 機器學習的相關數據行。
- 新的資料列 - 年和月 - 使用路徑資訊 (
puYear=X/puMonth=Y
)。
Pandas 程式代碼會處理此作業。 不過,實現 重現性 會變得困難,因為您必須:
- 共用程式代碼,這表示如果架構變更(例如數據行名稱變更),則所有使用者都必須更新其程式代碼,或
- 撰寫具有繁重負荷的 ETL 管線。
Azure 機器學習 數據表提供輕量機制,以串行化(儲存)檔案中的數據MLTable
載入步驟。 然後,您和小組成員可以 重現 Pandas 數據框架。 如果架構變更,您只會更新 MLTable
檔案,而不是在涉及 Python 數據載入程式代碼的許多位置更新。
複製快速入門筆記本或建立新的筆記本/腳本
如果您使用 Azure 機器學習 計算實例,請建立新的筆記本。 如果您使用 IDE,請建立新的 Python 腳本。
此外,Azure 機器學習 範例 GitHub 存放庫中也提供快速入門筆記本。 使用此程式代碼來複製及存取 Notebook:
git clone --depth 1 https://github.com/Azure/azureml-examples
cd azureml-examples/sdk/python/using-mltable/quickstart
mltable
安裝 Python SDK
若要將 NYC 綠色計程車數據載入 Azure 機器學習 數據表,您必須在 mltable
Python 環境中安裝 Python SDKpandas
,並使用下列命令:
pip install -U mltable azureml-dataprep[pandas]
撰寫 MLTable 檔案
mltable
使用 Python SDK 來建立 MLTable 檔案,以記錄數據載入藍圖。 為此,請將下列程式代碼複製並貼到 Notebook/Script 中,然後執行該程式代碼:
import mltable
# glob the parquet file paths for years 2015-19, all months.
paths = [
{
"pattern": "wasbs://nyctlc@azureopendatastorage.blob.core.windows.net/green/puYear=2015/puMonth=*/*.parquet"
},
{
"pattern": "wasbs://nyctlc@azureopendatastorage.blob.core.windows.net/green/puYear=2016/puMonth=*/*.parquet"
},
{
"pattern": "wasbs://nyctlc@azureopendatastorage.blob.core.windows.net/green/puYear=2017/puMonth=*/*.parquet"
},
{
"pattern": "wasbs://nyctlc@azureopendatastorage.blob.core.windows.net/green/puYear=2018/puMonth=*/*.parquet"
},
{
"pattern": "wasbs://nyctlc@azureopendatastorage.blob.core.windows.net/green/puYear=2019/puMonth=*/*.parquet"
},
]
# create a table from the parquet paths
tbl = mltable.from_parquet_files(paths)
# table a random sample
tbl = tbl.take_random_sample(probability=0.001, seed=735)
# filter trips with a distance > 0
tbl = tbl.filter("col('tripDistance') > 0")
# Drop columns
tbl = tbl.drop_columns(["puLocationId", "doLocationId", "storeAndFwdFlag"])
# Create two new columns - year and month - where the values are taken from the path
tbl = tbl.extract_columns_from_partition_format("/puYear={year}/puMonth={month}")
# print the first 5 records of the table as a check
tbl.show(5)
您可以選擇使用下列項目,選擇將 MLTable 物件載入 Pandas:
# You can load the table into a pandas dataframe
# NOTE: The data is in East US region and the data is large, so this will take several minutes (~7mins)
# to load if you are in a different region.
# df = tbl.to_pandas_dataframe()
儲存數據載入步驟
接下來,將所有數據載入步驟儲存到MLTable檔案中。 將數據載入步驟儲存在MLTable檔案中,可讓您在稍後的時間點重現 Pandas 資料框架,而不需要每次重新定義程式代碼。
您可以選擇將 MLTable yaml 檔案儲存至雲端記憶體,也可以將其儲存到本機路徑。
# save the data loading steps in an MLTable file to a cloud storage
# NOTE: the tbl object was defined in the previous snippet.
tbl.save(path="azureml://subscriptions/<subid>/resourcegroups/<rgname>/workspaces/<wsname>/datastores/<name>/paths/titanic", colocated=True, show_progress=True, overwrite=True)
# save the data loading steps in an MLTable file to local
# NOTE: the tbl object was defined in the previous snippet.
tbl.save("./titanic")
重要
- 如果共置 == True,則在目前未共置 MLTable yaml 檔案時,我們會將數據複製到同一個資料夾,而且我們會在 MLTable yaml 中使用相對路徑。
- 如果共置 == False,我們不會移動數據,而且我們會使用雲端數據的絕對路徑,並使用本機數據的相對路徑。
- 我們不支援此參數組合:數據位於本機、共置 == False 中,
path
以雲端目錄為目標。 請將本機數據上傳至雲端,並改用MLTable的雲端資料路徑。
重現數據載入步驟
現在,數據載入步驟已串行化為檔案,您可以使用load() 方法在任何時間點重現它們。 如此一來,您就不需要在程式碼中重新定義數據載入步驟,而且您可以更輕鬆地共用檔案。
import mltable
# load the previously saved MLTable file
tbl = mltable.load("./nyc_taxi/")
tbl.show(5)
# You can load the table into a pandas dataframe
# NOTE: The data is in East US region and the data is large, so this will take several minutes (~7mins)
# to load if you are in a different region.
# load the table into pandas
# df = tbl.to_pandas_dataframe()
# print the head of the data frame
# df.head()
# print the shape and column types of the data frame
# print(f"Shape: {df.shape}")
# print(f"Columns:\n{df.dtypes}")
建立數據資產以協助共用和重現
MLTable 檔案目前儲存在磁碟上,因此很難與小組成員共用。 當您在 Azure 機器學習 中建立數據資產時,MLTable 會上傳至雲端記憶體並「已設定書籤」。 您的小組成員可以使用易記名稱存取MLTable。 此外,數據資產已設定版本。
az ml data create --name green-quickstart --version 1 --path ./nyc_taxi --type mltable
注意
路徑會指向包含MLTable
檔案的資料夾。
讀取互動式會話中的數據資產
既然您已將 MLTable 儲存在雲端中,您和小組成員就可以在互動式會話中以易記名稱存取它(例如筆記本):
import mltable
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential
# connect to the AzureML workspace
# NOTE: the subscription_id, resource_group, workspace variables are set
# in a previous code snippet.
ml_client = MLClient(
DefaultAzureCredential(), subscription_id, resource_group, workspace
)
# get the latest version of the data asset
# Note: The version was set in the previous snippet. If you changed the version
# number, update the VERSION variable below.
VERSION="1"
data_asset = ml_client.data.get(name="green-quickstart", version=VERSION)
# create a table
tbl = mltable.load(f"azureml:/{data_asset.id}")
tbl.show(5)
# load into pandas
# NOTE: The data is in East US region and the data is large, so this will take several minutes (~7mins) to load if you are in a different region.
df = tbl.to_pandas_dataframe()
讀取作業中的數據資產
如果您或小組成員想要存取作業中的數據表,您的 Python 訓練腳本會包含:
# ./src/train.py
import argparse
import mltable
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('--input', help='mltable to read')
args = parser.parse_args()
# load mltable
tbl = mltable.load(args.input)
# load into pandas
df = tbl.to_pandas_dataframe()
您的作業需要包含 Python 套件相依性的 conda 檔案:
# ./conda_dependencies.yml
dependencies:
- python=3.10
- pip=21.2.4
- pip:
- mltable
- azureml-dataprep[pandas]
您會使用下列專案提交作業:
建立下列作業 YAML 檔案:
# mltable-job.yml
$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
code: ./src
command: python train.py --input ${{inputs.green}}
inputs:
green:
type: mltable
path: azureml:green-quickstart:1
compute: cpu-cluster
environment:
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04
conda_file: conda_dependencies.yml
在 CLI 中,建立作業:
az ml job create -f mltable-job.yml
撰寫 MLTable 檔案
若要直接建立 MLTable 檔案,建議您使用 mltable
Python SDK 來撰寫 MLTable 檔案,如 Azure 機器學習 數據表快速入門所示,而不是文本編輯器。 在本節中,我們將概述 Python SDK 中的 mltable
功能。
支援的檔案類型
您可以使用各種不同的檔案類型來建立 MLTable:
檔案類型 | MLTable Python SDK |
---|---|
分隔的文字 (例如 CSV 檔案) |
from_delimited_files(paths=[path]) |
Parquet | from_parquet_files(paths=[path]) |
Delta Lake | from_delta_lake(delta_table_uri=<uri_pointing_to_delta_table_directory>,timestamp_as_of='2022-08-26T00:00:00Z') |
JSON 行 | from_json_lines_files(paths=[path]) |
路徑 (建立具有資料串流路徑資料列的數據表) |
from_paths(paths=[path]) |
如需詳細資訊,請參閱 MLTable 參考檔
定義路徑
針對分隔文字、parquet、JSON 行和路徑,請定義 Python 字典清單,以定義要從中讀取的路徑:
import mltable
# A List of paths to read into the table. The paths are a python dict that define if the path is
# a file, folder, or (glob) pattern.
paths = [
{
"file": "<supported_path>"
}
]
tbl = mltable.from_delimited_files(paths=paths)
# alternatively
# tbl = mltable.from_parquet_files(paths=paths)
# tbl = mltable.from_json_lines_files(paths=paths)
# tbl = mltable.from_paths(paths=paths)
MLTable 支援下列路徑類型:
Location | 範例 |
---|---|
本機電腦上的路徑 | ./home/username/data/my_data |
公用 HTTP(s) 伺服器上的路徑 | https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv |
Azure 儲存體 上的路徑 | wasbs://<container_name>@<account_name>.blob.core.windows.net/<path> abfss://<file_system>@<account_name>.dfs.core.windows.net/<path> |
長期形式的 Azure 機器學習 數據存放區 | azureml://subscriptions/<subid>/resourcegroups/<rgname>/workspaces/<wsname>/datastores/<name>/paths/<path> |
注意
mltable
會處理 Azure 儲存體 和 Azure 機器學習 資料存放區上路徑的使用者認證傳遞。 如果您沒有基礎記憶體上數據的許可權,則無法存取數據。
定義 Delta Lake Tables 路徑的附註
相較於其他文件類型,定義讀取 Delta Lake 數據表的路徑會有所不同。 對於 Delta Lake 數據表,路徑會指向包含 「_delta_log」 資料夾和資料檔的單一資料夾 (通常是 ADLS gen2 上)。 支援時間移動 。 下列程式代碼示範如何定義 Delta Lake 資料表的路徑:
import mltable
# define the cloud path containing the delta table (where the _delta_log file is stored)
delta_table = "abfss://<file_system>@<account_name>.dfs.core.windows.net/<path_to_delta_table>"
# create an MLTable. Note the timestamp_as_of parameter for time travel.
tbl = mltable.from_delta_lake(
delta_table_uri=delta_table,
timestamp_as_of='2022-08-26T00:00:00Z'
)
如果您要取得最新版的 Delta Lake 資料,您可以將目前的時間戳傳遞至 timestamp_as_of
。
import mltable
# define the relative path containing the delta table (where the _delta_log file is stored)
delta_table_path = "./working-directory/delta-sample-data"
# get the current timestamp in the required format
current_timestamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
print(current_timestamp)
tbl = mltable.from_delta_lake(delta_table_path, timestamp_as_of=current_timestamp)
df = tbl.to_pandas_dataframe()
重要
限制: mltable
不支援從 Delta Lake 讀取數據時擷取數據分割索引鍵。
當您透過 mltable
讀取 Delta Lake 資料時,轉換mltable
extract_columns_from_partition_format
將無法運作。
重要
mltable
會處理 Azure 儲存體 和 Azure 機器學習 資料存放區上路徑的使用者認證傳遞。 如果您沒有基礎記憶體上數據的許可權,則無法存取數據。
檔案、資料夾和 Glob
Azure 機器學習 資料表支援從下列來源讀取:
- file(s),例如:
abfss://<file_system>@<account_name>.dfs.core.windows.net/my-csv.csv
- folder(s),例如
abfss://<file_system>@<account_name>.dfs.core.windows.net/my-folder/
- glob 模式(s),例如
abfss://<file_system>@<account_name>.dfs.core.windows.net/my-folder/*.csv
- 或者,檔案、資料夾和擷取模式的組合
支援的數據載入轉換
在 MLTable 參考檔案中尋找支援之資料載入轉換的完整最新詳細資料。
範例
Azure 機器學習 範例 GitHub 存放庫中的範例成為本文代碼段的基礎。 使用此指令將存放庫複製到您的開發環境:
git clone --depth 1 https://github.com/Azure/azureml-examples
提示
使用 --depth 1
僅將最新的認可複製到存放庫。 這樣可縮短完成作業所需的時間。
複製存放庫資料夾載入與 Azure 機器學習 資料表相關的範例:
cd azureml-examples/sdk/python/using-mltable
符號分隔檔案
首先,使用下列程式代碼從 CSV 檔案建立 MLTable:
import mltable
from mltable import MLTableHeaders, MLTableFileEncoding, DataType
# create paths to the data files
paths = [{"file": "wasbs://data@azuremlexampledata.blob.core.windows.net/titanic.csv"}]
# create an MLTable from the data files
tbl = mltable.from_delimited_files(
paths=paths,
delimiter=",",
header=MLTableHeaders.all_files_same_headers,
infer_column_types=True,
include_path_column=False,
encoding=MLTableFileEncoding.utf8,
)
# filter out rows undefined ages
tbl = tbl.filter("col('Age') > 0")
# drop PassengerId
tbl = tbl.drop_columns(["PassengerId"])
# ensure survived column is treated as boolean
data_types = {
"Survived": DataType.to_bool(
true_values=["True", "true", "1"], false_values=["False", "false", "0"]
)
}
tbl = tbl.convert_column_types(data_types)
# show the first 5 records
tbl.show(5)
# You can also load into pandas...
# df = tbl.to_pandas_dataframe()
# df.head(5)
儲存數據載入步驟
接下來,將所有數據載入步驟儲存到MLTable檔案中。 將數據載入步驟儲存在MLTable檔案中,可讓您在稍後的時間點重現 Pandas 資料框架,而不需要每次重新定義程式代碼。
# save the data loading steps in an MLTable file
# NOTE: the tbl object was defined in the previous snippet.
tbl.save("./titanic")
重現數據載入步驟
既然檔案具有串行化的數據載入步驟,您可以使用 方法在任何時間點 load()
重現它們。 如此一來,您就不需要在程式碼中重新定義數據載入步驟,而且您可以更輕鬆地共用檔案。
import mltable
# load the previously saved MLTable file
tbl = mltable.load("./titanic/")
建立數據資產以協助共用和重現
您目前已將 MLTable 檔案儲存在磁碟上,因此很難與小組成員共用。 當您在 Azure 機器學習 中建立數據資產時,MLTable 會上傳至雲端記憶體和「書籤」,這可讓您的小組成員使用易記名稱存取 MLTable。 此外,數據資產已設定版本。
import time
from azure.ai.ml import MLClient
from azure.ai.ml.entities import Data
from azure.ai.ml.constants import AssetTypes
from azure.identity import DefaultAzureCredential
# Update with your details...
subscription_id = "<SUBSCRIPTION_ID>"
resource_group = "<RESOURCE_GROUP>"
workspace = "<AML_WORKSPACE_NAME>"
# set the version number of the data asset to the current UTC time
VERSION = time.strftime("%Y.%m.%d.%H%M%S", time.gmtime())
# connect to the AzureML workspace
ml_client = MLClient(
DefaultAzureCredential(), subscription_id, resource_group, workspace
)
my_data = Data(
path="./titanic",
type=AssetTypes.MLTABLE,
description="The titanic dataset.",
name="titanic-cloud-example",
version=VERSION,
)
ml_client.data.create_or_update(my_data)
既然您已將 MLTable 儲存在雲端中,您和小組成員就可以在互動式會話中以易記名稱存取它(例如筆記本):
import mltable
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential
# connect to the AzureML workspace
# NOTE: subscription_id, resource_group, workspace were set in a previous snippet.
ml_client = MLClient(
DefaultAzureCredential(), subscription_id, resource_group, workspace
)
# get the latest version of the data asset
# Note: The version was set in the previous code cell.
data_asset = ml_client.data.get(name="titanic-cloud-example", version=VERSION)
# create a table
tbl = mltable.load(f"azureml:/{data_asset.id}")
# load into pandas
df = tbl.to_pandas_dataframe()
df.head(5)
您也可以輕鬆地存取作業中的數據資產。
Parquet 檔案
Azure 機器學習 數據表快速入門示範如何讀取 parquet 檔案。
路徑:建立映像檔的數據表
您可以建立包含雲端記憶體路徑的數據表。 此範例有數個位於雲端記憶體的狗和貓映像,位於下列資料夾結構中:
/pet-images
/cat
0.jpeg
1.jpeg
...
/dog
0.jpeg
1.jpeg
mltable
可以建構數據表,其中包含這些影像及其資料夾名稱(標籤)的儲存路徑,可用來串流影像。 下列程式代碼示範如何建立 MLTable:
import mltable
# create paths to the data files
paths = [{"pattern": "wasbs://data@azuremlexampledata.blob.core.windows.net/pet-images/**/*.jpg"}]
# create the mltable
tbl = mltable.from_paths(paths)
# extract useful information from the path
tbl = tbl.extract_columns_from_partition_format("{account}/{container}/{folder}/{label}")
tbl = tbl.drop_columns(["account", "container", "folder"])
df = tbl.to_pandas_dataframe()
print(df.head())
# save the data loading steps in an MLTable file
tbl.save("./pets")
下列程式代碼示範如何在 Pandas 資料框架中開啟儲存位置,並繪製影像:
# plot images on a grid. Note this takes ~1min to execute.
import matplotlib.pyplot as plt
from PIL import Image
fig = plt.figure(figsize=(20, 20))
columns = 4
rows = 5
for i in range(1, columns*rows +1):
with df.Path[i].open() as f:
img = Image.open(f)
fig.add_subplot(rows, columns, i)
plt.imshow(img)
plt.title(df.label[i])
建立數據資產以協助共用和重現
mltable
您目前已將檔案儲存在磁碟上,因此很難與小組成員共用。 當您在 Azure 機器學習 中建立資料資產時,mltable
會上傳至雲端記憶體和「書籤」,這可讓您的小組成員使用易記名稱存取 mltable
。 此外,數據資產已設定版本。
import time
from azure.ai.ml import MLClient
from azure.ai.ml.entities import Data
from azure.ai.ml.constants import AssetTypes
from azure.identity import DefaultAzureCredential
# set the version number of the data asset to the current UTC time
VERSION = time.strftime("%Y.%m.%d.%H%M%S", time.gmtime())
# connect to the AzureML workspace
# NOTE: subscription_id, resource_group, workspace were set in a previous snippet.
ml_client = MLClient(
DefaultAzureCredential(), subscription_id, resource_group, workspace
)
my_data = Data(
path="./pets",
type=AssetTypes.MLTABLE,
description="A sample of cat and dog images",
name="pets-mltable-example",
version=VERSION,
)
ml_client.data.create_or_update(my_data)
mltable
現在,儲存在雲端中,您和您的小組成員可以在互動式會話中以易記名稱存取它(例如筆記本):
import mltable
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential
# connect to the AzureML workspace
# NOTE: subscription_id, resource_group, workspace were set in a previous snippet.
ml_client = MLClient(
DefaultAzureCredential(), subscription_id, resource_group, workspace
)
# get the latest version of the data asset
# Note: the variable VERSION is set in the previous code
data_asset = ml_client.data.get(name="pets-mltable-example", version=VERSION)
# the table from the data asset id
tbl = mltable.load(f"azureml:/{data_asset.id}")
# load into pandas
df = tbl.to_pandas_dataframe()
df.head()
您也可以將資料載入作業。