How to load a dataset from a ZIP file to Jupyter Notebook or Visual Studio for data analysis using python and pandas. To load data from a zip file in jupyter notebook or visual studio code, you have to do something a little extra. There are 2 options to load a zip file in jupyter notebook. Import sys sys.executable in my Python 3 console, the output is. Usrbinpython3 and I'm able to import whatever libraries I've installed with pip3, no problem. When I do so in my Jupyter Notebook running a Python 3 kernel, the output is. Usrbinpython and the libraries that I've. Copy the Jupyter Notebook launcher from the menu to the desktop. Right click on the new launcher and change the Target field, change%USERPROFILE% to the full path of the folder which will contain all the notebooks. Double-click on the Jupyter Notebook desktop launcher (icon shows IPy) to start the Jupyter Notebook App.
I recently started playing guitar again after a long absence and wanted to start making some notes in a digital form. Unfortunately, I didn't find any good tools. There is TeX of course, which can do anything, but I was hoping for something a bit more WYSIWYGy. There are some very good tools available for musical scores (MuseScore, Frescobaldi), but I want something that is more like a traditional notebook with lots of notes interspersed with occasional musical notation (in both traditional and tablature forms).
So an obvious potential candidate is Jupyter (nee IPython), but it has no support for musical notation out of the box. But it is doable and in this post I'll walk through how I got it to work on my Mac. This is also my first attempt at using a Jupyter notebook as my blog post in Nikola so I'm kiling two birds with one stone.
I want something that is fairly easy to write the music in. MusicXML isn't too bad, except XML. What little I've seen of Liyponds markup looked pretty unfriendly for the simple use cases I have. A few days ago I stumbled across a Python library called abjad which looked just the ticket. As I write this I have it working for music on the staff but not tablature (I'm not sure it supports that) but I hope by the end of this post I'll have that figured out too!
Abjad relies on Lilypond, so first that has to be installed. It can be downloaded from http://lilypond.org/macos-x.html, and then the tarball needs to be uncompressed and the Lilypond.app folder dragged to /Applications. You need to follow the instructions at that link to set up a command line version too. I created a file /usr/local/bin/lilypond for that; my Homebrew install uses that folder so it is already in my path.
Next we need to install Abjad. You should ideally do this in a virtual environment. I use Anaconda and already have one set up, so can do the installation as follows; you may need to prefix this with
sudo
depending on your setup.Note how there are no spaces in the argument to
pip install
. The Abjad documentation shows spaces at the time I write this but that is incorrect; I have reported the issue and it should be corrected.It's also possible that the
development
and ipython
extensions are irrelevant. The error message above suggests they may be. However, I'm including them as that is what the documentation states.To have MIDI output recorded in the notebook, fluidsynth is needed. This requires Homebrew or MacPorts on a Mac. I have Homebrew so I do the installation with:
Well, that didn't go so well. It turns out Abjad releases aren't that frequent, and while this issue was fixed over six months ago (https://github.com/Abjad/abjad/issues/526) it hasn't made it into an official release yet (Abjad 2.16 as I write this). If you are using Python 3.4 or earlier this isn't a problem; its a Python 3.5 change.
So let's try get the bleeding edge version:
Once that is done, after a kernel reset in Jupyter we can try again:
Unfortunately, no output was produced. We can look at the source of the
show()
method by executing show??
in a cell. I've done that and am going to execute the same code in more detail below. First the part that should generate a PNG in a temporary file:Looking at that temporary folder, I see a '.ly' file but no .png. So it seems that this line:
is not working. Let's break that down:
That looks okay. What about the next step? If we look at that
as_png
function we see it returns the path, the lapsed formatting and rendering times, and a flag for success. We saw ((), 0.006474018096923828, 0.5328137874603271, False) as the output so success was False. I still have the .ly file around and it looks like what is failing is:So indeed that is the failure. If we look at its source with
systemtools.IOManager.run_lilypond??
:we can see that it writes to a log file, with a path given by abjad_configuration.lilypond_log_file_path. Let's look at that:
If you do a Google search for that error, you will find its been reported, and there is a workaround, which is:
Success! But what about tablature? It turns out that Lilypond uses a variant of Staff called TabStaff for tablature. Abjad does not have a TabStaff class but does allow you to override the tag used for a staff with a
context_name
argument:There are a few things left I'd like to do, and I will update this post if I figure them out. First there is a lot of blank space around the output it would be nice to be rid of. Secondly I want to do guitar chord diagrams. My understanding is that these can be done in Lilypond with a tag
fret-diagram-terse
but Abjad doesn't seem to support this so I will need to figure out how to extend it to support that. Watch this space.Project Jupyter is a non-profit, 100% open-source project. It develops software and web applications to support interactive data science and scientific computing. JupyterLab, Jupyter Notebook, and Jupyter Hub are the three key open source software developed by the team.
The Jupyter Notebook is a web app that lets you easily create and share documents that contain your live source code, markdown text, equations and visualizations - all in one canvas called a Notebook. It supports dozens of programming languages such as Python, R, Scala, Spark, and Julia. Data scientists use Jupyter Notebooks for several tasks - data analysis, cleaning, transformation, modelling, visualizations, machine learning, and so on. You can easily explore data using the popular Python libraries such as pandas, scikit-learn, ggplot2, TensorFlow.
You can easily set up and use Jupyter Notebook with Visual Studio Code, run all the live codes and see data visualizations without leaving the VS Code UI.
This blog post is a step-by-step guide to set up and use Jupyter Notebook in VS Code Editor for data science or machine learning on Windows. The post is written exclusively for the beginners in tech.
?️Set up our environment - Create a Jupyter Notebook
To set up your environment, you can either use a combination of WSL and VS Code, or Windows 10 with VS Code. I am using the former - Windows Subsystem for Linux (WSL) on Windows plus VS Code. Read this guide why I use WSL.
We will set up our Jupyter environment by creating a new Jupyter Notebook. If you have followed my WSL guide, you would have seen Ubuntu terminal by now. Let us create a Jupyter notebook. Open VS Code integrated terminal. Here is the quickest way to open VS Code integrated terminal inside Windows Subsystem for Linux (WSL). This will automatically open the Remote WSL. The view should look like this:
Now, press CNTRL+SHIFT+P button simultaneously using your keyboard. This will bring up a dropdown view in the VS Code Editor view. Enter Python: Create New Blank Jupyter Notebook and select it from the dropdown. Clicking on it should load Python extension if not loaded before.
Once connected, the first view should look like this:
The top right of the VS Code UI says 'Jupyter server: Not started'. This means Jupyter library is currently not installed inside WSL. You will also get two pops, one of which says, 'Data science libraries notebook and jupyter not installed'. Click on 'Install'. It will install Jupyter. Let it first install automatically.
Next, click on 'Yes' prompt where it says 'Data Science library ipykernel is not installed. Install?'.
One thing is to note that, you may see a pop up saying 'Error: 'Kernelspec' module not installed in the selected interpreter ({0}). Please re-install or update 'jupyter' '.
Many people have reported this. Here is a fix taken from official VS Code Python extension. In the integrated VS Code terminal, run both the commands one by one:
python3 -m pip install --upgrade pip
python3 -m pip install jupyter
Restart VS Code editor, and you should not see the pop up now. Let me know in the comments if the issue still persists. We will fix it together.
Congrats! You have set up the Jupyter library in VS Code inside the Windows Subsystem for Linux. I have written something in my Note. The final view should look like this.
⚙️ Work with code cells in the Notebook Editor
In the view, you should see M with a down arrow. Just below this, you will find cells to type in your code. Copy and paste these lines:
print(hello)
To run this code, click on the green run icon next to the cell. This will run the code cell.
How To Change Executable Path For A Jupiter Notebook Mac Os
The output of the code cell will appear just below the code cell.
Now, we will save our Jupyter notebook in our desired directory. I will save it in 'hello_python' folder. Press CNTRL+S button simultaneously using your keyboard.
Note the format of the file once you save it, it will be .ipynb format.
? Key Features of Jupyter Notebook Editor
The VS Code Jupyter integration is loaded with a lot of features.
?Python Interactive - Mix of Jupyter Notebook & Python Script
One of the finest features of the Python VS Code extension is the hybrid approach to use Jupyter notebook and a Python script. Confused? This is the Python Interactive window. Once we set this up, the final view will look like this:
Save the .ipynb file as python script. Click on the 'convert and save to a Python script' option located at the top of the Editor view.
Once you click on the 'convert and save to a Python script', VS code editor will open up a new file. Here is the view of the Untitled-1 file. The format of the file is .py
Save this file and rename it whatever you like it to. Make sure the file extension is .py. My file name is PythonScript. Click on OK.
Once you rename the file, the view will look like this:
You will get three options in this view - Run Cell, Run Above, and Debug Cell. Click on the options to see the results.
How To Change Executable Path For A Jupiter Notebook Machine
Now, in the Python extension's settings, we need to tick the Data Science: Debug Just My Code option. To do this, press CTRL+, button simultaneously using your keyboard. This will open up the Settings box. In the search box, paste this: Data Science: Debug Just My Code. Select this Option. Since I am using Windows Subsystem for Linux environment, I have first clicked on Remote [WSL:Ubuntu-18.04] and then checked the Debug Just My Code.
Now, close the Settings option. Let us get the Ipython Interactive view. In the file PythonScript.py file, click on any cell and press SHIFT+Enter keyboard button. This command opens up the Python Interactive window with the output of the code cell you just ran. It will have three sections: Python Script file code view, IPython Interactive, and a Console to run command.
Click on any code cell in the PythonScript window and press SHIFT+Enter keyboard button to get the output in the IPython Interactive window.
One of the key features of the IPython Interactive is the Console window in which you can run any code and get the output of that single code. Just enter your code and press SHIFT+Enter keyboard button.
? Key Features of IPython Interactive
The Ipython Interactive window has almost all the features of the Jupyter Notebook.
? Additional resources for continued learning
How To Change Executable Path For A Jupiter Notebook Mac Download
Here are the recommendations to learn more about VS Code Python extension's usage.
? What's Next
I am going to write about data structure and algorithms in Python. Meanwhile, if you are a newbie in Python, follow this track.
I will add many more posts under this track. Stay Tuned. Subscribe to my Blog.
Credits ? :
Official Microsoft Docs on Jupyter Notebook
Emojis taken from Emojipedia
Cover image built with BlogCover
Official Microsoft Docs on Jupyter Notebook
Emojis taken from Emojipedia
Cover image built with BlogCover