Python Jupyter Notebook

  1. Python Jupyter Notebook Examples
  2. Python Jupyter Notebook Docker
  1. Jupyter Notebook is built off of IPython, an interactive way of running Python code in the terminal using the REPL model (Read-Eval-Print-Loop). The IPython Kernel runs the computations and communicates with the Jupyter Notebook front-end interface.
  2. Creating a virtual environment for Jupyter Notebooks. A minimal Python install is. Sudo apt install python3.7 python3.7-venv python3.7-minimal python3.7-distutils python3.7-dev python3.7-gdbm python3-gdbm-dbg python3-pip Then you can create and use the environment.

The Jupyter Notebook used to be called the IPython Notebook. If you are running an older version of the IPython Notebook (version 3 or earlier) you can use the following to upgrade to the latest version of the Jupyter Notebook. If using Anaconda, update Jupyter using conda.

Many people use Python with notebooks, so let’s take a look at one possible way to enable a Jupyter external tool for Power BI Desktop. The following stepwise approach begins with simply opening Jupyter. It then progresses to creating and opening a notebook that includes Power BI’s server and database arguments. Finally, it works its way toward downloading a notebook definition contained in a GitHub gist and connects to Power BI’s tabular model to start to make this approach more useful.

This post continues a series of posts related to Python and Power BI. The first three parts of this blog series introduced some possible uses for Python connected to a Power BI model, how to setup a basic Python external tool, and how to both use it with a virtual environment and connect to the Tabular Object Model.

Open Jupyter: Foundational But Not Useful

I use the Anaconda distribution in these examples, and let’s consider how to simply start and open a notebook (vanilla Jupyter and nothing with JupyterLab). We only need a pbitool.json file at this stage because the goal is simply launch Jupyter–not even a notebook file. It’s not a useful example but provides a foundation on which we’ll build.

As discussed in Part 2, pbitool.json files define Power BI Desktop’s external tools. If you look at the Jupyter shortcut, it provides the inspiration for how to define Power BI’s external tool.

Python Jupyter Notebook

The JSON in this gist would need to be saved as a [tool].pbitool.json file and placed in C:Program Files (x86)Common FilesMicrosoft SharedPower BI DesktopExternal Tools.

Python jupyter notebook markdown

Note the path is for Python.exe, and arguments load the default Python environment and run the script to launch Jupyter.

There’s no value in simply opening Jupyter though. At this stage, it’s nothing more than a replacement for a shortcut. The real value is integrating Power BI Desktop more closely with the notebook.

Create and Open a Notebook (Hardcoded)

Taking it a step further, let’s create an empty notebook and write the currently open Power BI Desktop connection information to cells in the notebook. In this case, we need a Python script along with a new [tool].pbitool.json file.

The [tool].pbitool.json file has a few differences from the previous version. Most notably, it executes a Python script that I’ve named powerbinotebook.pyand placed in my C:Temp directory. You’ll also see the server and database arguments that Power BI Desktop uses to pass the current local connection (server:port and database GUID).

C:/Temp/ ”%server%” ”%database%”

The rest of the arguments start the default Python environment and launch Jupyter, but it’s important that the script runs before Jupyter launches. Why is that?

The Python script defines a nearly empty notebook for Jupyter and then launches it in Jupyter. Pay close attention to notebook_core, which contains the JSON definition for the notebook and writes sys.argv[1] and sys.argv[2] into the notebook for the Power BI server and database respectively. Each cell in the cells array will appear as a separate cell in the sample notebook. As required by the pbitool.json definition above, the Python script is located in, and you could obviously name and save your own to your location of choice.

The following video shows the basic script execution, where the Python script creates the notebook, launches Jupyter, and Jupyter launches the notebook.

Create and Open a Notebook Defined in a GitHub Gist

Taking it a step further, let’s shift the notebook definition to a GitHub gist instead of hardcoding it into the Python script. The gist contains the JSON and also placeholders for <<PowerBIServer>> and <<PowerBIDatabase>>, which the Python script will replace with the actual sys.argv[1] and sys.argv[2] values.
Sample gist (not embedded in the post):

I used the same [tool].pbitool.json file since only the contents of the script change. Note how the script is much shorter now that it no longer contains the notebook definition. This uses the requests library to get the JSON notebook template from the URL defined in gist_url. Note as well how replace swaps in the current values of the Power BI Server and Database.

Extending the Notebook Definition

Finally, let’s build a slightly more complex notebook using an updated script. As before, no modification is required for [tool].pbitool.json. Only the Python script updates.

Here is the updated notebook Gist for reference (not embedded in post):

As with the last example, the Python script downloads the new notebook definition contained in a different GitHub gist. Also as before, it replaces the <<PowerBIServer>> and <<PowerBIDatabase>> placeholders with the actual values passed into sys.argv from Power BI Desktop.

What’s new here is that this script downloads the ssas_api.pymodule mentioned in the Part 3 post, which is one among many possible ways to connect Python to AMO / TOM and other .NET libraries. The updated sample notebook loads the module and demonstrates basic model connectivity.

NOTE that the script intentionally does not overwrite a notebook once it’s created for a specific port number. To get a new blank template if you are testing this out simply requires closing and re-opening Power BI Desktop. Connecting to TOM in this sample also requires a Power BI Desktop connection with at least one existing table.

Here’s a look at the sample notebook in action. It illustrates two things: a basic connection to TOM, and the evaluation of a DAX query against the model open in Power BI Desktop.

Unlocking More


With a live connection to the Power BI Desktop model from Python, you can unlock a lot of possibilities. As described in Part 1, there are many examples ranging from data visualization to updating the model. I’m curious to hear your thoughts on how you might want to use Python in Power BI.

Let me know in the comments, and don’t forget to subscribe to the DataVeld blog.

Share this:

Like this:


Python Jupyter Notebook Examples

%d bloggers like this:

Jupyter Notebook(open source code), which beganas the iPython Notebook project, is adevelopment environment for writingand executing Python code. Jupyter Notebook is often used for exploratorydata analysis and visualization.

Python Jupyter Notebook Docker

Project Jupyter is the top-level project name for all of the subprojects underdevelopment, which includes Jupyter Notebook. Jupyter Notebooks can also runcode for other programming languages such as Julia andR.

How does Jupyter Notebook work?

The key piece of Jupyter Notebook infrastructure is a web application thatruns locally for creating and sharing documents that contain embedded code andexecution results.

Jupyter Notebook is an implementation of the text editors and IDEs concept. Learn how these parts fit together in the development environments chapter or view all topics.

How are IPython Notebook and Jupyter Notebook related?

IPython Notebook was the original project that proved that there was greatdemand among data scientists and programmers for an interactive, repeatabledevelopment environment. Jupyter Notebook became the new official name for theoverall project duringThe Big Splitafter the IPython Notebook project matured into distinct submodules such as theinteractive shell, notebook document format and user interface widgets tools.However, the IPython Notebook name sticks around as the Python backend forJupyter Notebook which is seriously confusing if you are searching the internetand come across both current and old articles that use all of these namesinterchangeably.

Python jupyter notebook linux

Jupyter Notebook beginner tutorials

Jupyter Notebook's powerful analysis and visualization environment can beintimidating even for experienced developers that are new to the tool. Thefollowing tutorials will explain the basics so you can quickly figure outyour own productive workflow.

  • Jupyter Notebook for Beginners: A Tutorialis a great place to start if you have never before used the tool.The guide covers installation, terminology, the user interface andhow to publish your notebooks to the web. Screenshots walk youthrough some of the more confusing bits as you are getting upand running.

  • First Python Notebook is a freeguide on analyzing data with Python and Jupyter Notebook. It coversmany 'Hello, World!'-style examples in both data analysis topics andmore general software development areas like Git, GitHub and Markdown.

  • IPython Or Jupyter?covers the evolution of the Notebook concept from its origins in the IPythonNotebook implementation through theIPython and Jupyter splitthat happened in 2015 that separated IPython Notebook into logical subprojects.The post kicks off with some fun lesser-known historical context on otherdata science notebook projects such as MATLAB and Mathematica to set the stagefor IPython and Jupyter's creation.

  • How to use Jupyter Notebooks in 2020 (Part 1: The data science landscape)is a high-level overview post that starts a series on Jupyter Notebooks.This first post covers why a tool like Jupyter Notebook is needed inthe broader landscape of data science.Part 2examines the growth of the Jupyter ecosystem and the jump from exploratoryanalysis notebooks to production notebooks.

  • Jupyter Notebook Best Practicescontains tips for beginners such as learning shortcuts and properlydocumenting the analysis you work on.

  • How to Version Control Jupyter Notebooksexplains how Jupyter Notebooks are stored in JSON, the issues with thatformat for source control and how to getaround the problem.

Example Notebooks

Example Notebooks are easy to fire up and see how other people are working.These resources are highly recommended after you read a couple of tutorialsand play around with the tool.

  • Peter Norvig's collection of Jupyter Notebooksis a an incredible resource for example projects.

  • Building and Exploring a Map of Reddit with Pythonis a detailed notebook that digs into public Reddit data while explainingthe 'what' and 'why' along the way.

  • Thisgallery of interesting Jupyter Notebooksprovides many great examples across numerous programming languages.

  • jupyter-samplescontains an extensive set of notebooks along with public datasets that can be used for analysis.

  • learn-python3 is gearedtowards Python beginners who want to learn basic syntax and standardlibrary features such as about string manipulation, functions anditeration.

Intermediate to advanced Jupyter Notebook tutorials

Once you get the hang of the basics there are a slew of ways to connectyour notebooks to third party APIsand use more advanced Python libraries with your code. These walkthroughscover a range of topics from niche tricks to common but advanced situationslike advanced interactive visualizations.

  • Advanced Jupyter Notebook Tricks — Part IandBuilding Interactive Dashboards with Jupyter (Part 2)have a ton more details on ways to set up Jupyter Notebooks as dashboardsand export results to other formats.

  • Creating Interactive Dashboards from Jupyter Notebooksshows how to use public Reddit data for a data analysis project asan example to display in dashboards running in a Jupyter Notebook.

  • mapboxgl-jupyter library alongwith thequickstartshow you how to visualize geospatial data within your notebooks.

  • Reproducible Data Analysis in Jupyteris a fantastic series of videos byJake Vanderplas that shows how to move yourcode from the interactive Jupyter environment into packaged, tested Pythoncode that is suitable for deployment to a productionenvironment.

  • 28 Jupyter Notebook tips, tricks and shortcutsexplains many of the lesser-known keyboard shortcuts and mechanismsto output settings.

  • Boost Your Jupyter Notebook Productivitycovers hotkeys, data plotting, shell commands, timing and other topicsyou will eventually want to handle within your notebooks as you getcomfortable in the environment.

  • Making Publication Ready Python Notebooksexplores the plugins that the author uses when creating and exportingreports from Jupyter.

  • PyData has an extensivelist of Jupyter Notebook talksfrom past events.JupyterConhas a similarly extensive talks list that is also worth watching.

  • Integrate Google Sheets and Jupyter Notebooksanswers the common question of how to extract data directly from a GoogleSheet and start working with it in your Jupyter Notebook. The screenshotshelp a lot to make sure you avoid getting lost in the sea of menus alongthe way.

  • Analyzing Cryptocurrency Markets using Pythonuses a freely-available Bitcoin API as a source data setfor a data analysis and visualization project in Jupyter.

  • nbdev: use Jupyter Notebooks for everythingshows how to use the nbdev tool to create a literateprogramming environment within a Jupyter Notebook so that you can doall of your debugging and refactoring there rather than switching betweena more traditional IDE and Jupyter.

  • Running Jupyter Notebooks on GPU on AWS: a starter guideexplains how to run notebooks on Amazon Web Services using agraphics-processing unit (video card), which for some machine learningsituations can result in significantly faster execution times.

  • Python & Big Data: Airflow & Jupyter Notebook with Hadoop 3, Spark & Prestowalks through a data pipeline that combines several commonly-useddata analysis tools with a Jupyter Notebook.

  • Ansible-jupyter-kernelis a kernel that allows you to run Ansible tasks andplaybooks from within your Jupyter environment.

  • Jupyter Notebooks in the IDEexplains how to use Jupyter files in Visual Studio Code orPyCharm with Jupytext, which defines thepairing information and notebook kernel.

  • The Notebook Wars is not atutorial but instead points to the weaknesses that become apparent whenusing Jupyter and the current generation of notebook projects. Thearticle raises many good points about barriers to entry although youcould also argue some of these issues have been mitigated by Jupyter, justnot as much as some people would like to see. Overall there is a lot toenjoy reading here and reflect on so that the community can continue makingJupyter a fantastic environment for development.

  • Creating Presentations with Jupyter Notebookshows how to make slides out of your cells so you can present yourwork like a traditional presentation.

  • The number of open source Jupyter Notebooks on GitHub is exploding andthis post attempts to estimate the growthusing Python, pandas and a scraped data set.

  • Reproducible Jupyter Notebooks with Dockerexplains when to use Docker in combination with JupyterNotebooks as well as the instructions for creating a dockerfile to buildyour images.

  • JupyterLab GPU Dashboardscontains a Bokeh server and TypeScript code for displayingGPU utilization charts.

What do you want to build Jupyter Notebook?

I want to learn how to code a Python web application using a framework.

Installing jupyter notebooks on windows

I've built a Python web app, now how do I deploy it?