I am trying to create a MS Access database from Python and wondered if it is possible to create a table directly from the pandas data frame. I know that I can use the pandas dataframe.to_sql() function to successfully write data to the SQLite database or using the sqlalchemy mechanism for some other database format (but not access unfortunately), but I canโt get all the parts go together. Here is the code snippet that I tested:
import pandas as pd import sqlalchemy import pypyodbc
I'm not sure that what I'm trying to do is possible even with the current packages that I use, but I wanted to check here before writing my own hacker framework in the MS Access table function. Maybe my sqlalchemy engine is configured incorrectly?
Here is the end of my error with mssql+pyodbc in the engine:
cursor.execute(statement, parameters) sqlalchemy.exc.DBAPIError: (Error) ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver] Could not find file 'C:\\INFORMATION_SCHEMA.mdb'. (-1811) (SQLExecDirectW)") u'SELECT [COLUMNS_1].[TABLE_SCHEMA], [COLUMNS_1].[TABLE_NAME], [COLUMNS_1].[COLUMN_NAME], [COLUMNS_1].[IS_NULLABLE], [COLUMNS_1].[DATA_TYPE], [COLUMNS_1].[ORDINAL_POSITION], [COLUMNS_1].[CHARACTER_MAXIMUM_LENGTH], [COLUMNS_1].[NUMERIC_PRECISION], [COLUMNS_1].[NUMERIC_SCALE], [COLUMNS_1].[COLUMN_DEFAULT], [COLUMNS_1].[COLLATION_NAME] \nFROM [INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_1] \nWHERE [COLUMNS_1].[TABLE_NAME] = ? AND [COLUMNS_1].[TABLE_SCHEMA] = ?' (u'FruitsAndPets', u'dbo')
and the final error for mysql+pyodbc in the engine:
cursor.execute(statement, parameters) sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'. (-3500) (SQLExecDirectW)") "SHOW VARIABLES LIKE 'character_set%%'" ()
I just want to note that I donโt care if I use sqlalchemy or pandas to_sql() . I'm just looking for an easy way to easily get the database in my MS Access database. If this dump is for JSON, then the loop function for inserting rows using SQL manually, regardless of whether it works well, I'll take it.