I have a pandas dataframe with many different columns and will like to insert specific columns into a mySQL database.
I understand from the documentation that the way to do so is to use to_sql like so:
import pandas as pd
import mysql.connector
from sqlalchemy import create_engine
engine = create_engine(db)
data.to_sql(name='dbtable', con=engine, if_exists = 'append', index=False)
However, when I run this in python3, I am getting the following ImportError:
Traceback (most recent call last):
File "myfile.py", line 130, in <module>
engine = create_engine('mysql+mysqlconnector://user:password@localhost:port/db')
File "/home/pohzihow/.local/lib/python3.5/site-packages/sqlalchemy/engine/__init__.py", line 387, in create_engine
return strategy.create(*args, **kwargs)
File "/home/pohzihow/.local/lib/python3.5/site-packages/sqlalchemy/engine/strategies.py", line 80, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/home/pohzihow/.local/lib/python3.5/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 110, in dbapi
return __import__('MySQLdb')
ImportError: No module named 'MySQLdb'
Upon doing some research I found out that actually mySQLdb does not support python3, but the documentation on pandas says that it requires the SQLAlchemy engine to connect to the database.
Is there a way to output my pandas dataframe into a mySQL database directly using python3?