Mito: Speed Up Dataset Manipulation with No Coding | by Angelica Lo Duca | Towards Data Science

I’m always looking for new tools to improve my Data Scientist activity. This time I came across Mito, a spreadsheet provided as a Python library, which allows you to manipulate a dataset in a simple and fast way, and above all in an interactive way.
Mito provides a graphical interface within the Jupyter Lab environment, so you can manipulate any dataset.
In practice, Mito combines the classic functionalities of spreadsheets (such as their user friendly usability), with all potentialities of Python. In fact, all the operations carried out within the interface are automatically translated into a Python code that can also be used elsewhere.
Mito provides the following features:
import/export datasets
add/delete columns to a dataset
build pivot tables
merge two datasets
plot charts
filter/sort columns
columns statistics
In this article, I give an overview of Mito, as well as a practical example of usage.
Mito is an interactive spreadsheet, provided as a Python library, which runs within Jupiter Lab, which must be installed in advance.
Mito can be easily installed through the following commands:
python3 -m pip install mitoinstallerpython3 -m mitoinstaller install
The Mito Official Documentation comes with a detailed description of common installation problems, which can help you if the installation process fails. In my case, the installation was ok.
Once installed, you must restart Jupyter Lab, if it is running, in order to enable Mito. You can run Jupyter Lab from command line through the following command:
jupyter lab
In order to run the Mito interactive interface, you can create a new notebook and write the following code in a cell:
import mitosheetmitosheet.sheet()
Each time you modify a dataset through the Mito interface, Mito generates the equivalent Python code in the cell below.
Datasets are stored as Pandas dataframes, which can be also manipulated directly in a cell.
The first time you run Mito, a new popup opens, asking for some information, such as your email and other similar stuff:
After Signed up, the Mito interactive interface starts within the notebook environment. You can enable the full screen modality, by clicking the top right button.
The interface provides the following menu bar:
Starting from the left, the following menu items are available:
undo — erase the last change done on the dataset;
import — load a new dataset from the file system. A popup opens, which permits you to browse among the directories of the filesystem. Supported formats include Excel (XLSX) and CSV;
export — download a manipulated dataset as a CSV to your local filesystem;
add column — add a new column to the dataset. You can change the column name, as well as the column values. In this last case, you can either enter values manually or calculate values from the other columns. It is sufficient to double click on the first row of the column to insert a formula;
delete column — erase a column completely;
pivot — build a pivot table. The resulting table is opened into a new tab, thus it can be manipulated separately;
merge — merge two datasets. You can choose among the following merge types:
graph — plot a graph for Exploratory Data Analysis (EDA). You can choose the columns associated to X and Y axes and then choose one of the supported graphs (see figure on the left for the supported graph types). All the graphs are generated in Plotly, one of the most famous Python libraries for Data Visualization. Mito saves the HTML file generated by Plotly for each graph. You can even copy the code produced to generate the graph;
save — save the current mitosheet;
replay — re-run the saved operations on new data.
If you click on a column name, a new popup opens, like the following one:
You can select the column type and order values (ascending or descending). You can even add one or more filters or a group of filters, for example to select only values matching some specific criteria. You can also search for specific values in a column.
Finally, in the Summary Stats tab, the distribution of your column is shown, as well as more specific summary information, including count, unique, top and frequency.
As use-case, I exploit the diamond.csv dataset, available on Kaggle. Firstly, I create a new notebook and in the first cell I write the following code:
import mitosheetmitosheet.sheet()
I select the first column, named Unnamed: 0, then I click on the DEL COL button, as shown in the following figure:
As a result, the column is deleted, as well as the corresponding Python code is generated in the cell below:
# Imported /Users/angelica/mitosheet_test/source/diamonds.csvimport pandas as pddiamonds_csv = pd.read_csv(r'/Users/angelica/mitosheet_test/source/diamonds.csv')# Deleted column(s) Unnamed: 0 from diamonds_csvdiamonds_csv.drop(['Unnamed: 0'], axis=1, inplace=True)
Now, I build a pivot table, which shows the average price per colour and cut type. I click the Pivot button and I select the following options in the popup window:
I also rename column names, simply by double clicking on the column name. With a single operation, Mito produces the following table:
Mito generates the corresponding code automatically:
# Pivoted diamonds_csv into df2unused_columns = diamonds_csv.columns.difference(set(['color']).union(set(['cut'])).union(set({'price'})))tmp_df = diamonds_csv.drop(unused_columns, axis=1)pivot_table = tmp_df.pivot_table(    index=['color'],    columns=['cut'],    values=['price'],    aggfunc={'price': ['mean']})# Flatten the column headerspivot_table.columns = [flatten_column_header(col) for col in pivot_table.columns.values]# Reset the column name and the indexesdf2 = pivot_table.reset_index()# Renamed price mean Fair to Fair in df2df2.rename(columns={"price mean Fair": "Fair"}, inplace=True)# Renamed price mean Good to Good in df2df2.rename(columns={"price mean Good": "Good"}, inplace=True)# Renamed price mean Ideal to Ideal in df2df2.rename(columns={"price mean Ideal": "Ideal"}, inplace=True)# Renamed price mean Premium to Premium in df2df2.rename(columns={"price mean Premium": "Premium"}, inplace=True)# Renamed price mean Very Good to Very Good in df2df2.rename(columns={"price mean Very Good": "Very Good"}, inplace=True)
Given the previous defined pivot table, I build a bar chart, which shows for each colour and cut type, the average price. Mito permits to add maximum three series in each graph. Thus in my graph, I include Ideal, Premium and Very Good.
Mito permits either to download the generated graph as a png file or to copy the graph code:
# Import plotly and create a figureimport plotly.graph_objects as gofig = go.Figure()# Add the bar chart traces to the graphfor column_header in ['Ideal', 'Premium', 'Very Good']:    fig.add_trace(        go.Bar(             x=df2['color'],            y=df2[column_header],            name=column_header        )    )# Update the title and stacking mode of the graph# See Plotly documentation for customizations: https://plotly.com/python/reference/bar/fig.update_layout(    xaxis_title='color',    yaxis_title='',    title='color, Ideal, Premium, Very Good bar chart',    barmode='group',)fig.show(renderer="iframe")
Since the graph is generated in Plotly, I can modify it by following the Plotly guidelines.
Now I load a second dataset, which contains for each cut type, its owner:
The idea is to merge the original dataset with the second one, previous loaded. I click the Merge button and I configure how to merge the two datasets, as shown in the following figure:
As a result, a new dataset is created, which includes all the columns of both the starting datasets:
As in the previous cases, Mito generates the Python code for the merging operation:
# Imported /Users/angelica/CNR/Git/mitosheet_test/source/cut_owners.csvimport pandas as pdcut_owners_csv = pd.read_csv(r'/Users/angelica/CNR/Git/mitosheet_test/source/cut_owners.csv')# Imported /Users/angelica/CNR/Git/mitosheet_test/source/cut_owners.csvimport pandas as pdcut_owners_csv_1 = pd.read_csv(r'/Users/angelica/CNR/Git/mitosheet_test/source/cut_owners.csv')# Merged diamonds_csv and cut_owners_csvtemp_df = cut_owners_csv.drop_duplicates(subset='cut') # Remove duplicates so lookup merge only returns first matchdf5 = diamonds_csv.merge(temp_df, left_on=['cut'], right_on=['cut'], how='left', suffixes=['_diamonds_csv', '_cut_owners_csv'])
Finally, I perform some operations on a single column. I can open the associated popup window by clicking the funnel icon near the column name. I consider the carat column, which is numeric and I sort it in ascending order, simply by clicking the Ascending button in the Filter/Sort tab. Then I create a new filter, which selects only rows with a value greater than 0.3.
Again, Mito generates automatically the Python code:
# Sorted carat in df5 in ascending orderdf5 = df5.sort_values(by='carat', ascending=True, na_position='first')# Filtered carat in df5df5 = df5[df5['carat'] > 0.3]
Now, I select the Summary Stats tab and Mito shows the following statistics on the carat column:
In this article, I have described Mito, a spreadsheet which permits to manipulate datasets very quickly. Mito can be easily run in Jupyter Lab, thus you just have to try it :)
The full code used in this article can be downloaded from my Github Repository.
If you have read this far, for me it is already a lot for today. Thanks! You can read more about me in this article.
You could subscribe for few dollars per month and unlock unlimited articles — click here.
towardsdatascience.com
towardsdatascience.com
alod83.medium.com
Disclaimer: This is not a sponsored article. I don’t have any affiliation with Mito or its authors. The article shows an unbiased overview of the framework, aiming at making data science tools accessible to the broader people.