0

I need to read the .mdb file in python which is in azure blob storage and export dataframe as as csv, I am able to read the csv but i am not able to read the .mdb file. Is there any other method to do so, Please feel free to give suggestion other than python.

What i tried:

from azure.storage.blob import BlockBlobService
import pandas as pd
import tables

STORAGEACCOUNTNAME= <storage_account_name>
STORAGEACCOUNTKEY= <storage_account_key>
LOCALFILENAME= <local_file_name>
CONTAINERNAME= <container_name>
BLOBNAME= <blob_name>

blob_service=BlockBlobService(account_name=STORAGEACCOUNTNAME,account_key=STORAGEACCOUNTKEY)
blob_service.get_blob_to_path(CONTAINERNAME,BLOBNAME,test.mdb)

# LOCALFILE is the file path
dataframe_blobdata = pd.read_csv(test.mdb)
James Lin
  • 153
  • 2
  • 10

1 Answers1

0

To read .mdb files from database it requires third party application called pyodbc and below is the sample code for reading .mdb files from python.

import csv
import pyodbc

MDB = 'c:/path/to/my.mdb'
DRV = '{Microsoft Access Driver (*.mdb)}'
PWD = 'mypassword'

conn = pyodbc.connect('DRIVER=%s;DBQ=%s;PWD=%s' % (DRV,MDB,PWD))
curs = conn.cursor()

SQL = 'SELECT * FROM mytable;' # insert your query here
curs.execute(SQL)

rows = curs.fetchall()

curs.close()
conn.close()

# you could change the 'w' to 'a' for subsequent queries
csv_writer = csv.writer(open('mytable.csv', 'w'), lineterminator='\n')

for row in rows:
    csv_writer.writerow(row)

For further information find the related SO1 SO2

SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15