How to Optimize Your Jupyter Notebooks with Embedded Power BI Reports

How to Optimize Your Jupyter Notebooks with Embedded Power BI Reports

As a Python user, one of the most time-consuming parts of any data science project I complete is producing clean, aesthetically pleasing visualizations throughout the exploratory data analysis process. While Python libraries like Matplotlib, Seaborn, and Plotly offer infinite flexibility, the standard visualizations often leave much to be desired. Searching through the documentation or StackOverflow to find the right code tweaks to make that unappealing graph ready for the eyes of a client or manager can eat up hours of precious time. 

 

On many occasions, I have found myself loading my data into Power BI to slice my way through the data exploration process in a fraction of the time. As of May of this year, Microsoft now allows me to take that work I’ve done in Power BI and embed it back into my Jupyter Notebook alongside all of the code that makes up the rest of my data science project.

How to Embed a Report into a Jupyter Notebook

In order to embed a report, it needs to be published in a workspace on the Power BI service. For my example, I downloaded the classic Iris dataset from the UCI Machine Learning repository and created a report with Power BI desktop. Using Power BI’s Small Multiples feature released this year, I can throw together a pretty decent-looking stacked histogram on a 2×2 grid in about 90 seconds and a half dozen clicks.

How to Embed a Report into a Jupyter Notebook

Now that I have a report, I’ll publish it to a workspace, and we’ll go through the steps to embed the report into a Jupyter Notebook. 

In order to work with Power BI within a notebook, we need to have the PowerBIClient library installed. This can be accomplished with a simple pip install.

How to Embed a Report into a Jupyter Notebook

After installing the library, we’ll import the Report and DeviceCodeLoginAuthentication classes from the Authentication module. 

Next, we need to authenticate our device. Running the piece of code below will produce a URL and code needed for authentication. Simply click the link and follow the instructions by entering the provided code and signing into Power BI. Text will appear in the cell output, letting you know authentication was successful.

Finally, we’ll need the workspace ID and report ID for the report we want to embed. We can find this by navigating to the Power BI service report and copying and pasting the group ID and report ID strings from the URL.

We’ll create variables with those text strings.

And finally, pass the group_id, report_id, and device_auth variables we’ve created as arguments for the Report() function. 

We now have all of the functionality of a Power BI report, complete with filters, tooltips, and the ability to navigate between any additional report pages we might create, right inside our Jupyter notebook in a fraction of the time it would have taken the average python user to write the code for the equivalent visuals.

Want to Learn More?

Have any questions, comments, or curiosities? Feel free to reach out to me about Power BI Reports on LinkedIn.

About Tessellation

We are a modern analytics consultancy. We enable and manage organizations’ analytics and self-service teams by educating people, optimizing technology, developing world-class products, and providing sustainable results. Curious to know how we can level up your organization’s analytics? Click here!

Interested in joining the Tessellation Team as a data analyst, Tableau expert, dashboard designer, or data scientist? We’re hiring! Check out our latest job listings on our website and on our Linkedin page!

Subscribe to Our 'Data Cap' Newsletter!

Want a monthly insights from the Tessellation Team with tips, tricks, and secrets to improve your analytics?

Sign up below and we'll deliver articles, events, and how to's straight to your inbox.
Comments are closed.