This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_csv.py
More file actions
38 lines (33 loc) · 1.43 KB
/
check_csv.py
File metadata and controls
38 lines (33 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from azure.storage.blob import BlobServiceClient
from s3connector import azure_connection_string
from azure.core.exceptions import AzureError
from io import StringIO
import pandas as pd
def download_blob_file(container_name, file_name):
try:
blob_service_client = BlobServiceClient.from_connection_string(azure_connection_string)
container_client = blob_service_client.get_container_client(container_name)
blob_client = container_client.get_blob_client(file_name)
data = blob_client.download_blob().readall().decode('utf-8')
return data
except AzureError as e:
print(f"Error retrieving file from Azure Blob Storage: {e}")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
def count_records_in_csv(csv_data):
try:
data = StringIO(csv_data)
df = pd.read_csv(data)
num_records = len(df)
return num_records
except Exception as e:
print(f"An error occurred while counting records in the CSV file: {e}")
return None
# Specify the container name and file name
container_name = 'historic' # Update with your container name
file_name = 'company_overviews.csv' # Update with your file name
csv_data = download_blob_file(container_name, file_name)
num_records = count_records_in_csv(csv_data)
print(f"The number of records in the CSV file is: {num_records}")