Forum Discussion
Federico Fontana
Sep 05, 2017Copper Contributor
Reading .csv stored in Azure Blob Storage from Excel
I've been able to create a storage account, then a container, than a blob storing a .csv file. I've successfully been able to download the .csv file from Azure itself and using Python as well via the...
- Sep 05, 2017
Hi, don't load the connection, edit the connection
then in the Power Query screen, filter the 'Name' column to get the files you want, then click on the column 'Content' to actual get the data.
Sorry my example sheets have only one column, but you can use the Power Query features to transform the files.
hareesh94
Dec 26, 2022Copper Contributor
To read a CSV file stored in Azure Blob Storage from Excel in Python, you can use the azure-storage-blob library and the pandas library.
Here's an example of how you can do it:
# Import the necessary libraries
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
import pandas as pd
# Get the connection string for your storage account
# Replace `<your_storage_account_name>` and `<your_storage_account_key>` with your storage account name and key
connection_string = "DefaultEndpointsProtocol=https;AccountName=<your_storage_account_name>;AccountKey=<your_storage_account_key>;EndpointSuffix=core.windows.net"
# Create a BlobServiceClient using the connection string
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
# Get the container client for the container where your CSV file is stored
# Replace `<your_container_name>` with the name of your container
container_client = ContainerClient.from_connection_string(connection_string, container_name="<your_container_name>")
# Get the blob client for the CSV file
# Replace `<your_csv_file_name>` with the name of your CSV file
blob_client = BlobClient.from_connection_string(connection_string, container_name="<your_container_name>", blob_name="<your_csv_file_name>.csv")
# Download the CSV file from Azure Blob Storage
csv_stream = blob_client.download_blob()
# Read the CSV file into a pandas DataFrame
df = pd.read_csv(csv_stream)
# Now you can work with the data in the DataFrame
print(df)
This code will connect to your storage account, download the CSV file from the specified container and blob, and https://codethreads.dev/python/read-csv-in-python/. You can then work with the data in the DataFrame as needed.
I hope this helps!