Thank you for reaching out to Microsoft Q&A forum!
To save a pandas dataframe as a CSV file in Azure Blob Storage from Azure ML Notebook, you can use the azure-storage-blob
library. I tried to repro with the below code snippet for your reference:
from azure.storage.blob import BlobServiceClient
import pandas as pd
import io
# Define your Azure Blob Storage account details
account_name = '<your_account_name>'
account_key = '<your_account_key>'
container_name = '<your_container_name>'
blob_name = '<your_blob_name>'
# Create a BlobServiceClient object
blob_service_client = BlobServiceClient(account_url=f"https://{account_name}.blob.core.windows.net", credential=account_key)
# Convert your pandas dataframe to a CSV string
df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
csv_string = df.to_csv(index=False)
# Convert the CSV string to a bytes object
csv_bytes = str.encode(csv_string)
# Upload the bytes object to Azure Blob Storage
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
blob_client.upload_blob(csv_bytes, overwrite=True)
Please provide the Blob Storage account details in the above code and execute. In Blob storage you can find the CSV file as below:
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful.