Created
March 11, 2017 18:40
-
-
Save Swalloow/9dbbba9579b87548c71af68337f95299 to your computer and use it in GitHub Desktop.
DataFrame to MySQL
This file contains hidden or 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
def save_db(df, table): | |
try: | |
engine = create_engine("mysql+mysqldb://root:"+"password"+"@localhost/"+table, encoding='utf-8') | |
conn = engine.connect() | |
# Save dataframe to database | |
df.to_sql(name=table, con=engine, if_exists='append') | |
print("Saved successfully!!") | |
except: | |
traceback.print_exc() | |
finally: | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment