.NET Core with Jupyter Notebooks – Available today | Preview 1

Maria

November 6th, 2019

Please Note: The instructions in this post are obsolete. For the latest instructions please visit the .NET Interactive repo. For more information please look at our Preview 2 announcement for more information.

When you think about Jupyter Notebooks, you probably think about writing your code in Python, R, Julia, or Scala and not .NET. Today we are excited to announce you can write .NET code in Jupyter Notebooks.

Try .NET has grown to support more interactive experiences across the web with runnable code snippets, interactive documentation generator for .NET core with dotnet try global tool, and now .NET in Jupyter Notebooks.

Build .NET Jupyter Notebooks

To get started with .NET Notebooks, you will need the following:

.NET Core 3.0 SDK

Jupyter : You can install Jupyter on your machine using Anaconda. For alternative ways to install Jupyter please check out the Jupyter’s Project official documentation.

Open the Anaconda Prompt (Windows) or Terminal (macOS) and verify that Jupyter is installed and present on the path:

> jupyter kernelspec list python3 ~\jupyter\kernels\python3

Next, in an ordinary console, install the dotnet interactive global tool:

> dotnet tool install -g dotnet-try

Install the .NET kernel by running the following within Anaconda Prompt:

> dotnet try jupyter install [InstallKernelSpec] Installed kernelspec .net-csharp in ~\jupyter\kernels\.net-csharp .NET kernel installation succeeded [InstallKernelSpec] Installed kernelspec .net-fsharp in ~\jupyter\kernels\.net-fsharp .NET kernel installation succeeded

You can verify the installation by running the following again in the Anaconda Prompt:

> jupyter kernelspec list .net-csharp ~\jupyter\kernels\.net-csharp .net-fsharp ~\jupyter\kernels\.net-fsharp python3 ~\jupyter\kernels\python3

Features

The initial set of features we released needed to be relevant to developers, with Notebook experience as well as give users new to the experience a useful set of tools they would be eager to try. Let’s have a look at some of the features we have enabled.

The first thing you will need to be aware of is when writing C# or F# in a .NET Notebook, you will be using C# Scripting or F# interactive.

You can either explore the features listed below locally on your machine or online using the dotnet/interactive binder image.

For the online documentation, please go to the Docs subfolder located in C# or F# folders.

List of features

Display output : There are several ways to display output in notebooks. You can use any of the methods demonstrated in the image below.

Object formatters : By default, the .NET notebook experience enables users to display useful information about an object in table format.

HTML output : By default .NET notebooks ship with several helper methods for writing HTML. From basic helpers that enable users to write out a string as HTML or output Javascript to more complex HTML with PocketView.

Importing packages : You can load NuGet packages using the following syntax:

#r "nuget:<package name>,<package version>"

For Example

# r "nuget:Octokit, 0.32.0" # r "nuget:NodaTime, 2.4.6" using Octokit; using NodaTime; using NodaTime.Extensions; using XPlot.Plotly;

Charts with XPlot

Charts are rendered using Xplot.Plotly. As soon as users import XPlot.Plotly namespace into their notebooks( using Xplot.Ploty; ), they can begin creating rich data visualizations in .NET.

Please check the .NET Notebook online for more documentation and samples.

.NET Notebooks perfect for ML .NET and .NET for Apache® Spark™

.NET notebooks bring iterative, interactive experiences popular in the worlds of machine learning and big data to .NET.

ML.NET

ML.NET with Jupyter Notebooks

.NET notebooks open up several compelling scenarios for ML.NET, like exploring and documenting model training experiments, data distribution exploration, data cleaning, plotting data charts, and learning.

For more details on how you can leverage ML.NET in Jupyter notebooks, check out this blog post on Using ML.NET in Jupyter notebooks. The ML.NET team has put together several online samples for you to get started with.

.NET for Apache® Spark™

Big Data for .NET

Having notebooks support is indispensable when you are dealing with Big data use cases. Notebooks allow data scientists, machine learning engineers, analysts, and anyone else interested in big data to prototype, run, and analyze queries rapidly.

So how can .NET developers and major .NET shops keep up with our data-oriented future? The answer is .NET for Apache Spark, which you can now use from within notebooks!

Today, .NET developers have two options for running .NET for Apache Spark queries in notebooks: Azure Synapse Analytics Notebooks and Azure HDInsight Spark + Jupyter Notebooks. Both experiences allow you to write and run quick ad-hoc queries in addition to developing complete, end-to-end big data scenarios, such as reading in data, transforming it, and visualizing it.

Option 1: Azure Synapse Analytics ships with out-of-the-box .NET support for Apache Spark (C#).

Option 2: Checkout the guide on the .NET for Apache Spark GitHub repo to learn how to get started with .NET for Apache Spark in HDInsight + Jupyter notebooks. The experience will look like the image below.

Get Started with the .NET Jupyter Notebooks Today!

.NET kernel brings interactive developer experiences of Jupyter Notebooks to the .NET ecosystem. We hope you have fun creating .NET notebooks. Please checkout our repo to learn more and let us know what you build.