Skip to content

Instantly share code, notes, and snippets.

@juandesant
Created November 7, 2023 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juandesant/e77b00bccf6cfda04abc3467e75f2531 to your computer and use it in GitHub Desktop.
Save juandesant/e77b00bccf6cfda04abc3467e75f2531 to your computer and use it in GitHub Desktop.
Export tables from an Access database
# This script assumes that [mdbtools][1] are installed, for instance with
# `brew install mdbtools`
# [1]: https://github.com/mdbtools/mdbtools
# It also assumes that [pandas][2] and [pandas_access][3] are installed,
# [2]: https://pandas.pydata.org/
# [3]: https://pypi.org/project/pandas_access/
# which you can do with
# `pip install pandas pandas_access`
# or
# `pip install pandas_access`
# if you already have pandas (i.e., in a Conda environment)
# `file_name` contains the full or relative path to the Access file
file_name = ‘path_to_access_file.mdb’
for table in mdb.list_tables(file_name):
df = mdb.read_table(file_name, table)
df.to_excel(f'{file_name}-{table}.xlsx')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment