Rerun analysis on new data
A step-by-step guide to reusing your Python code to refresh a report with new data.
Last updated
A step-by-step guide to reusing your Python code to refresh a report with new data.
Last updated
© Mito
If you're looking to rerun an analysis in streamlit or dash, see this documentation.
This step-by-step tutorial shows you how rerun an analysis you’ve previously created on a new data set. It uses the change imports taskpane.
In this tutorial, we’ll create a pivot table on the june_loans.csv
file, and refresh that pivot table on the july_loans.csv
file.
I’m importing june_loans.csv, but the same approach works regardless if I’m importing csv files, excel files, dataframes, or a combination of them.
Here, I’ve created a pivot table that shows us the average loan amount for each purpose of receiving a lone.
Now that we’ve created an analysis, we can easily rerun this analysis on a new dataset using the change imports feature. In the Mito toolbar, click on Dataframes
> Change imported data
.
The change imports taskpane shows us all the data we’ve imported to our analysis. In this example, we only have one csv file, june_loans.csv
. However, if I imported additional csv files, excel files, or dataframes, they would also appear in this list.
To select new data for the analysis, click on the file in the taskpane and select whether you want to replace the data with a file or dataframe.
In this example, we want to replace june_loans.csv
with july_loans.csv
, so we will select “Replace with file”.
Follow the prompts in the taskpane to select the new file. It works the same as importing files using the Mito file explorer.
In this example, we’ll select july_loans.csv
.
Once you’ve selected the file, press the Update button at the bottom of the taskpane.
Once you’ve selected new data, the taskpane will show you the changes you are about to make. In this example, we see that we’re about to replace the june_loans.csv
file with the july_loans.csv
file.
After double checking that we’ve properly selected the new data for each import that we want to change, press the Change Imports button at the bottom of the taskpane.
If the analysis updated successfully, you should see a notification on the right-hand side of the screen that says “Successfully replayed analysis on new data”. Updating the data has done a few things:
It updates the data in Mito. Here, we see that our analysis has the tabs july_loans
and july_loans_pivot
instead of june_loans
and june_loans_pivot
. We also notice that the data in the pivot table is different than the original pivot table we created.
It updates the generated code. Notice that the generated code now imports the july_loans.csv
file instead of the june_loans.csv file and that the dataframe name is updated accordingly.
Our analysis updated successfully!
In this scenario we still had access to the original data. If on the other hand, you do not have access to the original data, when you rerun the mitosheet.sheet()
call the change imports taskpane will automatically open. It will include an error message that tells you which files need to be updated.
When you change the imported data, the dataframe names used in the generated code update as well. In the example we just looked at, the pivot table was originally called june_loans_pivot
and updated to july_loans_pivot
. If you’ve written custom python code that references the Mito generated dataframes, this can cause issues, so make sure to rename the sheet tabs in Mito so that they have a consistent name. For example, if in the original analysis we updated the pivot table name from june_loans_pivot
to average_loan_amounts
, then when we rerun the analysis on july_loans.csv
, the pivot table will still be named average_loan_amounts
.