To export data from an Azure ML table to a SharePoint List, you can follow these steps:
- Use the Azure ML SDK to read the MLTable data into a Pandas DataFrame. Here’s a code snippet to retrieve data:
from azureml.core import Workspace, Dataset import pandas as pd # Connect to your Azure ML workspace ws = Workspace.from_config() # Load your dataset (replace with your dataset name) dataset = Dataset.get_by_name(ws, 'your_ml_table_name') df = dataset.to_pandas_dataframe()
- You’ll need to authenticate to SharePoint. You can use Microsoft’s
Office365-REST-Python-Client
library to handle SharePoint operations. Ensure you have an app registration in Azure AD with permissions to the SharePoint site.from office365.runtime.auth.authentication_context import AuthenticationContext from office365.sharepoint.client_context import ClientContext from office365.sharepoint.listitems.listitem import ListItem # Authenticate to SharePoint url = "https://your-sharepoint-site-url" context_auth = AuthenticationContext(url) context_auth.acquire_token_for_user('your_email@domain.com', 'your_password') ctx = ClientContext(url, context_auth)
- Convert the data in the DataFrame to the format expected by the SharePoint List.
- Loop through the DataFrame and add items to the SharePoint list.
# Define the SharePoint list name list_title = "Your SharePoint List Name" sharepoint_list = ctx.web.lists.get_by_title(list_title) for _, row in df.iterrows(): item = sharepoint_list.add_item({ "ColumnName1": row["Column1"], "ColumnName2": row["Column2"], # Map other columns as necessary }).execute_query()
- You can incorporate this code as a step within a PromptFlow pipeline, automating it to trigger whenever the ML table is updated.
Make sure you install required packages with pip install azureml-core office365-rest-python-client
and set up permissions for SharePoint and Azure ML access.
This setup should help in pushing data from your Azure ML table to SharePoint. Let me know if you need further customization!