Use C# in Jupyter Notebooks with Polyglot Notebooks

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey folks I want to show you how you can use Jupiter notebooks and net together using the new polyglot notebooks extension for visual studio code this extension has been around for a little bit under the name of.net interactive but in November of 2022 Microsoft rebranded it to polyglot notebooks just because it supports so many languages you're going to see what I mean when I show you here so if you're not familiar with jupyter notebooks that's okay uh you'll kind of get the drift here I'm not going to go over installing it in this but I do have an article on that if you check the description of this video uh here I am in Visual Studio code and I have a number of extensions installed uh including uh both Jupiter notebooks and the maybe more critical one uh polyglot uh notebooks okay so here's polyglot notebooks it's currently in preview as of the time of this recording it's fairly effective I like it a lot um and the way that you work with it is once you've installed this extension once you've installed Jupiter notebooks on your machine this really is actually just a kernel for Jupiter so it plugs into the existing Jupiter install and it just lets you run jupyter notebooks using more languages such as C sharp F-sharp even HTML CSS not CSS SQL uh other languages it's pretty crazy it hits the name polyglot it's not just.net anymore let's take a look at how this runs okay so I'm going to open up the command palette by doing Ctrl shift p on Windows it's probably command shift p on on a Mac but in here I'm going to type in polyglot no look and notice I get a number of things but I'm going to choose to create a new blank notebook okay and when you do that it asks you hey do you want to create this as a dib or an ipy notebook I typically work with these iPod notebooks from jupyter notebooks so I choose that one um and then I ask you for your default language uh I like C sharp so I'm going to do C sharp but you know there's a number of languages you can choose to use so you can change your language over here to C sharp F sharp HTML JavaScript custom query language or cake you go mermaid which is really marked down for diagrams pretty cool Powershell CQ SQL and I'm I haven't actually looked at Value storage um notably absent here is VB uniformly called vb.net so we have.net languages just not VB so let's take a look at what this is what we can do with it the first thing we can do here is we can actually go in and we can run C sharp code so I can say uh int num burritos to buy hope you're not hungry is five I can say decimal price per burrito is 3.80 uh decimal decimals begin with an m um and I can click play to run this or I could hit control enter both work and that's a Cell It's a solo of code I can also have have cells of markdown so I can put in mark down here this is a header in markdown with some paragraph that's gonna be very uh very familiar to anybody who's worked with jupyter notebook's very same concept so here's the cool thing about this is that these these variables are available between cells so now I can add a new code cell and I can say decimal uh total for lunch is equal to numb burritos to buy and notice how I get my intellisense I like that times price per burrito and if I wanted to I could do console uh right line total for lunch that's actually not the most ideal way of doing this but we see here it's actually nineteen dollars and if I decide I want a different number of burritos or you know maybe burritos cost a little bit more let's say burritos not cost nine cents extra I can rerun the cell and now I could rerun this cell as well I get a different value okay uh so pretty cool now Twitter notebooks uh has this kind of cool feature where the last V if you in to sell a could sell with a variable is the last thing and you run it it's just displayed automatically so we didn't even actually need to console right line that so that's pretty neat uh there's some other neat things going on here so let's add a class so I'm going to say hey public class uh student I'm gonna give this oh uh didn't need to move on to another cell I think shift uh enter is probably what did that for me um and I'm going to give it a public uh string name get set and I might say public uh decimal GPA get set so now I have a class and I can actually Define that class and I can create a new student I'll say student Mass equals new using my implicit new or Target type new here um and I'll use my curly boys create a new one there's the shift enter for you again uh with a name of Matt and a GPA of let's brag I guess my GPA is currently 4.0 as a master's student um but if I run this well I'm going to have a new variable matte and if I have it this is my last last variable in a Cell just online at its own without a semicolon at the end that's actually important it actually prints out all the properties of the object right here so that's pretty cool so I can do I can do that here if I if I need to now if I want to have a list uh I can I can do that as well I can say I can add a using system collections generic I actually don't need this this using but I tend to do it anyway probably got notebook seems to have this this as a kind of an automatically imported namespace but I can say list of student s equals new list and let's say I'm going to add map to that list and I might add also add another another student here so I would say students dot add um new student and I'm going to call the student's name it's going to be jimothy it's a fantastic name with the GPA of negative seven Genesis not doing so well um and now if I choose to have my list as my last uh object here is my cell now I get to see all my students in there so very cool stuff this is really handy for if you wanted to mix together uh code and markdown um maybe just play around with some objects play around with your public API or public API you're investigating it can do this if you want to document your your application and share it with other people on your team or other people on the internet for like a public Source uh of Open Source uh Library you could do that as well we can mix together documentation and markdown and also you know c-sharp or F sharp or what other languages that we wanted to now a couple key tricks before we close uh variables you can always take a look at what variables are in memory for your server by clicking on variables and that will let you see them that doesn't seem to be populating for me here so that's Matt tempting the demo Gods I suppose but if I run all my cells yep okay there we are so now they they populate so if you can always rerun your cells you can run cells in any order you can repeatedly run cells as many times as you want and you can also click on variables to see all of your variables that you have now it is possible to use a c-sharp variable in an F-sharp cell or vice versa there's a lot of other things you can do including installing nuget packages but I want to just kind of keep it simple as far as what we can do with jupyter notebooks uh sorry polyglot notebooks which let you.net development and other languages inside of a jupyter notebook environment so take a look at my article if you have any more questions leave a comment I'm happy to answer them um I think this is really exciting I'm particularly loving this for working with ml.net and data science experiments there so expect more content for me on that area but thanks for watching and let me know what you think [Music] [Music] thank you
Info
Channel: Matt on Data Science
Views: 2,603
Rating: undefined out of 5
Keywords: Data Science, Machine Learning, Dotnet, CSharp, FSharp, VS Code, Jupyter, Jupyter Notebooks, .NET Interactive, Polyglot Notebooks
Id: ObHyyrIWElk
Channel Id: undefined
Length: 9min 17sec (557 seconds)
Published: Fri Dec 16 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.