
Fastest way to Convert Jupyter Notebooks into Analytics Reports! (using Quarto)
Transform messy Jupyter notebooks into polished HTML reports with Quarto. Learn how to create professional, client-ready reports that effectively communicate data science insights to stakeholders. Using a telecom customer churn analysis example, we'll cover: - Converting notebooks to formatted HTML reports - Customizing layouts and interactive elements - Adding business context to technical analysis - Publishing and sharing reports effectively Perfect for data scientists and analysts who need to present technical work to business audiences. Link to Code: https://github.com/KeithGalli/telecom-churn-analysis Quarto Crash Course Video: https://youtu.be/_VKxTPWDhA4?si=kcbQ8M9p6HH5QE2w Share your work with Posit Connect Cloud: https://pos.it/keith_qc Video by @KeithGalli Video timeline! 0:00 - Video Overview & Accessing Code/Data 1:46 - Rendering Jupyter Notebook as HTML Output 3:30 - Making quick improvements to our HTML Report (adjusting YAML parameters, hiding code/output cells) 8:15 - Understanding the Business Context & Insights from our Analysis and adding written details to report. 14:30 - Improving page formatting (margins, body size, etc) 17:30 - Adding business recommendations for our telecom client 21:00 - Further aesthetic improvements (larger font-size, organizing info into columns, using a qmd file, etc.) 30:17 - Publishing our HTML report using Posit Connect Cloud #python #jupyter #quarto
image: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
Hey what's up everyone and welcome back to another video. So in this video we're going to solve a common data science data analysis challenge and that is ultimately bridging the gap between the you know data science notebook or wherever you write your code and the presentations the slideshows the reports that you often share with business stakeholders. So in this video we will see how we can take a notebook that looks like this you know a bunch of code everywhere a bunch of graphs but it's a bit messy there's you know a lot here and it's hard to process by just looking at this alone and we'll see how we can turn it into a much more human readable much more digestible html analytics report as you can see here with descriptions of you know what the different graphs means and some recommendations for a telecom company.
So the data set that we'll be working off of in this video comes from this Kaggle data set it is telecom customer churn data so given a bunch of customers and information about the customers like how much they're spending per month how long they've been with the company etc can we predict or not even necessarily can we predict but can we see why certain people are churning meaning they're leaving our telecom company versus others are not. So this data is available on Kaggle I think it originally came from IBM but you can also access it via the github repo that is linked in the description.
So we'll see how we can take a messy notebook that has some analysis and insights and turn it into an html report using Quarto.
Rendering the notebook with Quarto
So I think the first step in this is that we have this notebook and I think we can see what happens if we render this with Quarto by default as an html file. So what I might do is that you can access all these files via the github link so feel free to clone the repo but I might just make a copy just so I can kind of see the changes and what we've done of this notebook paste it and I might call this something like report.ipythonnotebook and both the starting file analysis.ipythonnotebook and the ending file this report that we're going to be working off are both in the github repo so feel free to see the before and after.
But the first step that I want to do is take this notebook I'm going to open up a terminal window and I guess I can do that in vs code with this and I want to render this ipythonnotebook as an html file. If you're not super familiar with Quarto we've posted a Quarto crash course recently. A link to that is in the description so you can understand all the basics of Quarto and a video like this will make more sense but you also can watch this without any prior Quarto knowledge and kind of get a feel of what you can do with Quarto. But I'm going to go ahead and I'm going to do a Quarto render report.ipythonnotebook and it's kind of cool that I can just create files off of these Jupyter notebooks directly and we see we have a report.html created so if I look at my files we see a report.html.
Okay we see we have a file that looks like this and basically it just looks very very similar to our notebook so it's not quite super digestible yet. I think we can do some things to immediately make it more digestible for a potential client. So imagine we are working for this telecom company and we're a consulting company and they hired us to be like hey why are our customers leaving? We want to get it into a format where we can bring back our analysis and be like hey this is why and we're not quite there yet. We don't want them to see the code. We don't want to see a lot of the aspects of this so let's go ahead and make some immediate changes that will make this a bit easier to share with a client.
Hiding code and output with YAML parameters
The first thing you'll want to do is we should above our title add some of the yaml parameters so with any sort of Quarto document we're going to add these parameters and I think it's fine that you do this in a markdown cell. I think you could also do this in a raw text cell within your Jupyter notebook but I'm going to make this format. We'll start with an html. I don't need to add a title right now but one thing that I do want to probably do is I'm going to make the code echo equal and false. We'll make the code not show up so I'm going to go ahead and now rerun this. We can look at this file now and refresh this and now we don't see any of our code so that's a good starting point.
Adding narrative and insights
If we look at the distribution of this information we see that their tenure so how long they've been with the company the likelihood that they're going to churn is super super high it's a great percentage of those new customers and it's still pretty high the first few months here in this histogram we see so if you're a new customer we want to pay more attention to you because you're at the greatest risk of churning as we can see by this so understanding new customers are likely to churn that's helpful insight for our customer.
We also see that if we look at the relative monthly charges we kind of get you know low churn low churn low churn if the price is cheap but as we start getting into these higher price points the percentage of customers in that bin that that monthly charge range there's a higher percentage of them that are going to churn if they're paying these higher monthly charges another insight from this numeric data. And then finally we see that basically as the total amount of charges so I would think of this as tenure times monthly charges if people stick around and have spent a lot of money with our telecom company uh they're they're less likely to churn you know so we want to keep our customers happy in the early months because once they've spent some money and you know know our service know our product then they're less likely to turn so another insight from all of this.
So I'm doing things like this actually getting the insights and thinking about them and then let's actually write some text on the screen that kind of captures some of this stuff so I'll go ahead and capture some of those thoughts and then you can also look through these bar charts and see some other insights on these more binary variables so like gender has very little effect if they're a senior citizen yes they're more likely to churn so maybe they're not understanding the technology as well or something maybe there's more hurdles it seems like if someone has a partner independence they're less likely to churn so maybe just more important that they have our service they're less you know independent and can just you know pick up and leave and move to a new new provider more more people and their family depend on the current service. We see that fiber optic gives us a much higher likelihood of churn as well as month-to-month contracts are great great indicators of churn so we want to probably move as many people to one year and two-year contracts so some more insights I'm just kind of speaking out but let's put this all on the screen in our notebook.
Cool let's uh rerun this real quick and just see what we have now one good thing to note real quick is if you are generating these Quarto reports via the command line and via a jupyter notebook one thing that you'll want to do is add is potentially add this render and then this dash dash execute parameter this will just make sure that all of your jupyter notebook cells are run so that it's not just using what's already on the screen it's actually rerunning the code as well to produce the report. Okay so let's run that command.
Okay and now let's look at our report okay so we should see some text now pop up on the screen. Okay we see that that's good we'll improve the formatting soon that's good we have some more insights maybe we also add some insights at the top so before this initial data exploration section so just kind of talking about the process that we're doing in general so what I could do here is add you know right below this title some more text so maybe I'm just giving a bit of an overview on what we're doing here and let's say our consulting company is called like alpha consulting co and this is just kind of a you know a high level what this report is providing.
Layout and formatting improvements
Converting to Quarto markdown and adding columns
Adding interactivity and publishing
You still have your same code you're still your same notebook that you could play around with and tweak things more but now we have a nice like more human readable way to display our insights and findings pretty cool stuff pretty quick that we can do this.
