MySQL#
Install Dependencies#
[ ]:
! pip install pymysql
! pip install plotly
! pip install ipython-sql
!pip install jupyter-server-proxy
[ ]:
import pandas as pd
[ ]:
from sqlalchemy import create_engine
DB_USER = "USER"
DB_PASSWORD = "PASSWORD"
DB_URL = "URL"
engine = create_engine(f'mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_URL}:3306/mysql')
[ ]:
df = pd.read_sql_query("show tables", engine)
df
[ ]:
df = pd.read_sql_query("select * from TABLE_NAME", engine)
df
D-Tale#
For this example, we create a Pandas DataFrame with random data and then save it to a MySQL database. We then use D-Tale to visualize the data.
[ ]:
import random
table = []
metrics = ["Accuracy","Precision"]
labels = ["L0","L1","L2"]
for _ in range(100):
for metric in metrics:
for label in labels:
table.append({"Metric": metric,"Value": random.uniform(0.0, 1.0), "Label": label})
[ ]:
df = pd.DataFrame(table)
[ ]:
df.to_sql(con = engine, name = "Demo", if_exists='replace', index = False)
[ ]:
!pip install dtale
[ ]:
import dtale
import dtale.app as dtale_app
dtale_app.JUPYTER_SERVER_PROXY = True
d = dtale.show(df,host="0.0.0.0",)
[ ]:
from IPython.display import Markdown
from IPython.core.magic import register_cell_magic
import os
DTALE_URL = d._main_url
@register_cell_magic
def markdown(line, cell):
return Markdown(cell.format(**globals()))
[ ]:
%%markdown
[DTale]({DTALE_URL})