In [1]:
pip install pyodbc
In [2]:
import pyodbc
import pandas as pd
import numpy as np
## Microsoft Access 檔案名稱為 0000_1010801-1080331.accdb
conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\\DATA\\Python data\\練習\\0000_1010801-1080331.accdb')
SQL = 'SELECT * FROM [1010801-1080331]' ## 1010801-1080331為資料表名稱
cur = conn.cursor()
cur.execute(SQL)
list = cur.fetchall()
desc = cur.description
cur.close()
conn.close()
df_column = pd.DataFrame(np.array(desc))
df = pd.DataFrame(np.array(list), columns=df_column[0])
df.head()
Out[2]:
In [3]:
df = df.set_index("編號", drop=True)
df.head()
Out[3]:
In [ ]:
沒有留言:
張貼留言