Pulling MS access tables and putting them in data frames in python

后端 未结 1 624
南旧
南旧 2021-02-09 15:43

I have tried many different things to pull the data from Access and put it into a neat data frame. right now my code looks like this.

from pandas import DataFram         


        
相关标签:
1条回答
  • 2021-02-09 16:20

    Consider using pandas' direct read_sql method:

    import pyodbc
    import pandas as pd
    ...
    cnxn = pyodbc.connect('DRIVER={{Microsoft Access Driver (*.mdb, *.accdb)}};DBQ=' + \
                          '{};Uid={};Pwd={};'.format(db_file, user, password)
    
    query = "SELECT * FROM mytable WHERE INST = '796116'"
    dataf = pd.read_sql(query, cnxn)
    cnxn.close()
    
    0 讨论(0)
提交回复
热议问题