Created
March 17, 2021 16:55
-
-
Save jaimevalero/a6040dc76abf5434dd26e5d298b3fd30 to your computer and use it in GitHub Desktop.
cost_chart_treemap.py
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
import pandas as pd | |
import pymysql | |
import matplotlib.pyplot as plt | |
def get_query(SQL): | |
con = pymysql.connect(host='MYSQL_REPLACE', user='MYUSUARIO_REPLACE',password='MY_PASSWORD_REPLACE') | |
return pd.read_sql(SQL , con=con) | |
def get_table(db,table=""): | |
"""Return all rows from table """ | |
if (table == "" and "." in db) | (db == "" and "." in table): | |
return get_query(f"SELECT * FROM {db}{table}") | |
else: | |
return get_query(f"SELECT * FROM {db}.{table}") | |
df = get_query("""SELECT conguration_items_organization.ci_name , | |
conguration_items_organization.ci_type , | |
conguration_items_organization.organization , | |
costs.precio_mes | |
FROM inventario.conguration_items_organization , inventario.costs | |
WHERE conguration_items_organization.ci_name COLLATE utf8_unicode_ci = costs.ci_name AND | |
conguration_items_organization.ci_type COLLATE utf8_unicode_ci = costs.ci_type""") | |
df | |
fig = px.treemap(df, path=['organization', 'ci_type', 'ci_name'], values='precio_mes') | |
fig.update_layout( | |
autosize=True, | |
width=800, | |
height=800,) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment