What do I need to read Microsoft Access databases using Python?

后端 未结 12 2249
面向向阳花
面向向阳花 2020-11-27 15:59

How can I access Microsoft Access databases in Python? With SQL?

I\'d prefere a solution that works with Linux, but I could also settle for Windows.

I only r

12条回答
  •  天涯浪人
    2020-11-27 16:11

    To read an Access database as a pandas dataframe (Windows).

    This is a very quick and easy solution that I have used successfully for smaller databases.

    You can read an Access database by making a permanent link to Excel and saving that file (it takes a couple of clicks), link here:

    https://support.office.com/en-gb/article/Connect-an-Access-database-to-your-workbook-a3d6500c-4bec-40ce-8cdf-fb4edb723525

    You can then simply read that Excel file as a pandas dataframe.

    So, for example, save the linked Excel file as 'link_to_master.xlsx' in location \FileStore\subfolder1\subfolder.

    Run the following in python:

    import pandas as pd
    import os
    os.chdir('\\\\FileStore\\subfolder1\\subfolder') #sets the folder location
    df = pd.read_excel('link_to_master.xlsx') # reads the Excel file
    df
    

    Consider frequency of the link refresh if you are re-visiting your python script. i.e. The link between Excel and Access is static.

提交回复
热议问题