iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📰

Introduction and Notes on Mito: An Easy-to-Use Spreadsheet for Streamlit

に公開
2023/09/08

This is a memorandum for Mito, which is implemented with Streamlit.
I have included images and brief explanations, so even first-time users can understand the features of Mito.
Also, since it's Streamlit, you can easily implement it as an app.
I think it's very useful for those who want to process data and create graphs...

https://blog.streamlit.io/data-analysis-with-mito-a-powerful-spreadsheet-in-streamlit/
https://docs.trymito.io/mito-for-streamlit/streamlit-overview
I recently learned about Mito and was surprised at how convenient it is. Despite being free, it can perform tasks similar to Tableau. Furthermore, it comes with AI, allowing for effortless data editing.
I've just started using it, so I'll add more notes as I find them.

Spreadsheets and Graphs

This is what it looks like when first displayed.

Here is an example of the graphs. In addition to scatter plots, it can display various types like histograms and line charts.

You can also display them with detailed classifications.

Demo Code

I'm retrieving the DataFrame from Seaborn.
I have also published a general-purpose version at the bottom of the article, so please give it a try.

import streamlit as st
import seaborn as sns
import matplotlib.pyplot as plt
from mitosheet.streamlit.v1 import spreadsheet

st.header("MitoSheet Demo")

df = sns.load_dataset('tips')

# Display the dataframe in a Mito spreadsheet
final_dfs, code = spreadsheet(df)

# Display the final dataframes created by editing the Mito component
# This is a dictionary from dataframe name -> dataframe
st.write(final_dfs)

# Display the code that corresponds to the script
st.code(code)

You can run it with the following:

streamlit run XXX.py

Memorandum

Most commands available for DataFrames can be done.

Getting Unique Values

It's df.unique(). You can display them by right-clicking a column name and selecting "View Unique Values".

By unchecking the marks, you can filter out those values.
It's very convenient for removing outliers immediately.

Displaying Summary Statistics

It's df.describe(). You can display them by right-clicking a column name and selecting "View Summary Stats".

It reflects the results every time you edit the data.

Handling Missing Values

Right-click a column name and select "Fill NaN Values". It handles missing values for you.
You can specify the replacement value as a custom number, the mean, etc.

Splitting Columns

Right-click a column name and select "Split Text to Columns".
You can split columns by specifying a delimiter. You can also set the delimiter yourself.

Changing Data Types

You can easily change the data type from "Dtype" by clicking on the column name.

  • bool: True/False
  • int: Numeric (Integer)
  • float: Numeric (with decimal point)
  • str: String
  • datetime: Date
  • timedelta: Elapsed time

Mito AI

Mito has built-in AI. If you have an OpenAI API key set up, you can chat with Mito AI.
Even without an API key, it seems they allow up to 100 free uses.
 
This AI isn't capable of everything; it can execute commands related to DataFrames like those mentioned above. For example, drawing graphs is outside the scope of pandas, so it cannot do that.

Moreover, it feels quite clumsy charming. Sometimes it says it can't do the same command it did before, or it performs unintended actions... I believe this will improve through things like fine-tuning.

Creating New Columns

In the image below, I created a column called "sex+smoker" from the existing "sex" and "smoker" columns, and it handles it even with a fairly rough prompt.

Getting Correlation Coefficients

It's df.corr(). You tell the AI to "calculate the correlation coefficient."

It displayed df.corr() as a new sheet.

Statistical Calculations

It also performs calculations. For example, when you want statistical data like calculating mean ± 3σ.


*For some reason it didn't work well, and I struggled for about 10 minutes to take this screenshot.
→ I was able to generate it consistently with a different prompt.

Prompt: "Create one df where rows are total_bill and tip, and columns are mean-3σ, mean, mean+3σ."
So it creates it as a new dataframe. This might be applicable to other calculations as well.
 
There are many other functions besides these, and I will update them as I go.

Code to Analyze Any Data

If you want to chat with Mito AI, please set up an OpenAI API Key. The settings are configured to read only Excel or CSV files.

from mitosheet.streamlit.v1 import spreadsheet
import streamlit as st
import pandas as pd

if not hasattr(st.session_state, "df_mito"):
    st.session_state["df_mito"]= pd.DataFrame()

st.header("Data analysis using Mito")
st.write("***You can perform data analysis using Mito. Please upload a file of your choice.***")
upload_file = st.file_uploader('Select the file you want to analyze', type=['csv', 'xlsx'])
if upload_file is not None:
    if upload_file.name.endswith("csv"):
        st.session_state.df_mito=pd.read_csv(upload_file)
    elif upload_file.name.endswith("xlsx"):
        st.session_state.df_mito=pd.read_excel(upload_file)
    final_df,code=spreadsheet(st.session_state.df_mito)

    st.write(final_df)
    st.code(code)

Discussion