I want to access the data in a Microsoft Access database. I have some .accdb and .mdb files and want to read them in Python.
From my research, pyodbc can only be used on Windows platform, but I am working on Mac OS X. I am new to Python.
The other option is if I could export the data from the database to a csv and then use in python.
Any help or starting would be highly appreciated.
You can run your Access database from anywhere in the world where there is an Internet Connection. Users running Access on a Mac will get the same experience as users running it on their PC. There are no code changes required as Access is, in reality, running on a Windows machine.
To connect Python to Access: Add the path where you stored the Access file (after the syntax DBQ=). Don't forget to add the MS Access file extension at the end of the path ('accdb') Add the table name within the select statement.
Microsoft Office Access is not available for Linux but there are plenty of alternatives that runs on Linux with similar functionality. The best Linux alternative is LibreOffice - Base, which is both free and Open Source.
Python can connect to and work with a wide variety of database applications, MS Access database is one of them. We'll walk through how to use the pyodbc library to interact with an Access database.
On Mac OSx and Ubuntu 18.04 you can use pandas_access
From the documentation:
import pandas_access as mdb db_filename = 'my_db.mdb' # Listing the tables. for tbl in mdb.list_tables(db_filename): print(tbl) # Read a small table. df = mdb.read_table(db_filename, "MyTable")
On Ubuntu you may need to run:
sudo apt install mdbtools
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With