Azure ML | Export Data from Azure MLTable to SharePoint List

Avni Bhatt 120 Reputation points
2024-11-09T02:02:21.86+00:00

Hello,

I have processed data in a Azure ML table which gets updated via PromptFlow periodically. How can I export this Azure MLTable to a SharePoint List?

Thank You,

Avni Bhatt

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,968 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,837 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,908 questions
{count} votes

Accepted answer
  1. Amira Bedhiafi 26,491 Reputation points
    2024-11-10T13:24:24.89+00:00

    To export data from an Azure ML table to a SharePoint List, you can follow these steps:

    1. 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()
         
      
    2. 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)
         
      
    3. Convert the data in the DataFrame to the format expected by the SharePoint List.
    4. 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()
         
      
    5. 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!

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.