You can use the Pandas.ExcelWriter() by outputting to Bytes.IO instead of a file. Either the storage or data lake endpoints will work about the same.
Setting up the file:
from pandas import ExcelWriter
from pandas import DataFrame
import pandas
import io
import xlsxwriter
#import whichever client you plan to use
from azure.storage.blob import BlobServiceClient, BlobClient
#OR
from azure.storage.filedatalake import DataLakeServiceClient
d = {'col1': [1, 2], 'col2': [3, 4]}
df = pandas.DataFrame(data=d)\
io = io.BytesIO()
# Use a temp filename to keep pandas happy.
writer = pandas.ExcelWriter('temp.xlsx', engine='xlsxwriter')
# Set the filename/file handle in the xlsxwriter.workbook object.
writer.book.filename = io
# Write the data frame to the StringIO object.
df.to_excel(writer)
writer.save()
Using Data Lake client:
connStr = "<data lake url>"
token = "<SAS toke>"
dl_service_client = DataLakeServiceClient(account_url=connStr, credential=token)
file_client = dl_service_client.get_file_client("<container name>", "<file path>")
file_client.create_file ()
file_client.append_data(data, offset=0, length=len(data))
file_client.flush_data(len(data))
Blob client:
connStr = "<storage url>"
token = "<SAS toke>"
blob_service_client = BlobServiceClient(connStr, token)
blob_client = blob_service_client.get_blob_client("<container name>", "<file path>")
blob_client.upload_blob(io.getvalue(), overwrite = True)