Extracting Code
Extracting Code
Imports
python
Copy code
import os
from azure.storage.blob import BlobServiceClient
import pandas as pd
import json
os: This module provides functions for interacting with the operating system.
azure.storage.blob: Contains classes and methods to interact with Azure Blob
Storage.
pandas as pd: Pandas is used for data manipulation and analysis, particularly with
CSV files.
json: This module is used to work with JSON data.
Configuration
python
Copy code
# Configuration - replace with your actual values
connect_str = "YOUR_CONNECTION_STRING" # Replace this with your Azure
Storage connection string
container_name = "customer360data" # Replace this with your Azure Blob
Storage container name
BlobServiceClient: This client allows you to interact with the Azure Blob Storage
service.
ContainerClient: This client allows you to interact with a specific container within
Azure Blob Storage.
Extract CSV Function
python
Copy code
def extract_csv(blob_name):
"""
Extract CSV data from the specified blob.
"""
try:
blob_client = container_client.get_blob_client(blob_name)
downloader = blob_client.download_blob()
return pd.read_csv(downloader.download_as_bytes())
except Exception as e:
print(f"Error extracting CSV data from {blob_name}: {e}")
return None
Main Function
python
Copy code
def main():
# Extract and display customer profiles
customer_profiles = extract_csv("customer_profiles.csv")
if customer_profiles is not None:
print("Customer Profiles:")
print(customer_profiles.head())
else:
print("Failed to extract customer profiles")
This ensures that the main() function is called when the script is executed directly.
Summary
4o