<jupyter_start><jupyter_text>\[_In case you’re unable to see the atoti visualizations in GitHub, try viewing the notebook in [nbviewer](https://nbviewer.org/github/atoti/notebooks/blob/master/notebooks/burritos/main.ipynb)._]<jupyter_code># import relevant libraries
import re

import atoti as tt
import numpy as np
import pandas as pd
# load in data
df = pd.read_csv("./data/burritos_01022018.csv")
# explore column headers
df.columns
# look at first 5 rows of data
df.head()
# explore shape and central tendency
df.describe()
# use regular expression to remove () from columns
# use .replace() to remove : from columns
df.columns = [re.sub("([\(\[]).*?([\)\]])", "", x).strip() for x in df.columns]
df.columns = [x.replace(":", "_").strip() for x in df.columns]
df.columns
# check if there are nulls in column
df.isnull().any()
# check the % of the column that is null
df.isnull().sum() / df.shape[0]
# create an atoti session and store dashboard files in ./content
session = tt.create_session(
    config={
        "port": 9000,
        "user_content_storage": "./content",
    },
)
# scale circumference, volume, fillings, length, mass, and cost data
from sklearn.preprocessing import MinMaxScaler

scaler = MinMaxScaler()
burrito_vars_norm = df.loc[:, ["Circum", "Volume", "Length", "Mass", "Cost"]]

# change 0-1 scaline to 0-10 scale for readability
bnorms = scaler.fit_transform(burrito_vars_norm) * 10

# create new columns for normalized values in our datframe (df)
df[["Circum_norm", "Volume_norm", "Length_norm", "Mass_norm", "Cost_norm"]] = bnorms
# create new dataframe for variables so they can be used in a visualization platform
# melt reshapes the data so that we have 1 column with circum, volume, length, mass, and cost as features & 1 with values.
# we increaste the number of rows by 5x and decrease the number of columns by 4.
burrito_variables = pd.melt(
    df.reset_index(),
    id_vars=["Location", "Burrito"],
    value_vars=["Circum_norm", "Volume_norm", "Length_norm", "Mass_norm", "Cost_norm"],
)
burrito_variables
# upload dataframe to atoti session
burrito_table = session.read_pandas(df, table_name="burritos")
burrito_table.head()
# create data cube
cube = session.create_cube(burrito_table)
# create hierarchies, levels, and measures
h = cube.hierarchies
l = cube.levels
m = cube.measures
# create new measures (examples)
m["five"] = 5
m["lenXwrap"] = m["Length.MEAN"] * m["Wrap.MEAN"]
# create pivot table visual / example
session.visualize("exploration 1")
# create scatterplot visual /example
session.visualize("scatter plot neighborhood yelp google")
# add reformatted data to table to visualize
burrito_var_table = session.read_pandas(
    burrito_variables,
    table_name="burrito_variables",
    keys=["Location", "Burrito", "variable"],
)
# join main dataframe with new burrito_var_table
burrito_table.join(burrito_var_table)
# create value measure in atoti with values for each of the burrito variables that we made above (mass, circum, cost, etc.)
m["value"] = tt.agg.mean(burrito_var_table["value"])
m["aggvalue"] = tt.agg.mean(
    m["value"], scope=tt.scope.origin(l["Location"], l["Burrito"], l["variable"])
)
# create radar chart
session.visualize("radar chart final")
# new data for yelp gauge
m["four"] = 4
# new data for google gauge
m["four_google"] = 4.25
session.link(path="/#/dashboard/1be")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12958579881656804, 'fraction_numerical': 0.009467455621301775, 'mean_word_length': 5.091891891891892, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '92828', 'license': 'Apache-2.0', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1076, 'n_words': 353, 'path': 'notebooks/burritos/main.ipynb', 'repo_name': 'joohiang/notebooks', 'size': '3380'}