Created
March 16, 2020 16:51
-
-
Save MinaGabriel/a2915282bd6294a0a99ff57cb107838d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pandas as pd | |
import mysql.connector | |
from sqlalchemy import create_engine | |
# ====== Connection ====== # | |
# Connecting to mysql by providing a sqlachemy engine | |
engine = create_engine('mysql+mysqlconnector://myhu:password@192.168.68.102/dbname', echo=True) | |
list_hello = ['hello1', 'hello2'] | |
list_world = ['world1', 'world2'] | |
df = pd.DataFrame(data={'hello': list_hello, 'world': list_world}) | |
# engine.execute("CREATE DATABASE dbname") #create db | |
print(engine.table_names()) | |
df.to_sql(name='helloworld', con=engine, if_exists='replace') | |
print(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment