Now we will consider alternatives to Jupyter Notebooks. We will look at:
- Jupyter QT Console
- Spyder
- Rodeo
- Python interpreter
- ptpython
The first alternative we will consider is the Jupyter QT Console; this is a Python interpreter with added functionality, aimed specifically for data analysis.
The following screenshot shows the Jupyter QT Console:
It is very similar to the Jupyter Notebook. In fact, it is effectively the Console version of the Jupyter Notebook. Notice here that we have some interesting syntax. We have In [1], and then let's suppose you were to type in a command, for example:
print ("Hello, world!")
We see some output and then we see In [2].
Now let's try something else:
1 + 1
Right after In [2], we see Out[2]. What does this mean? This is a way to track historical commands and their outputs in a session. To access, say, the command for In [42], we type _i42. So, in this case, if we want to see the input for command 2, we type in i2. Notice that it gives us a string, 1 + 1. In fact, we can run this string.
If we type in eval and then _i2, notice that it gives us the same output as the original command, In [2], did. Now, how about Out[2]? How can we access the actual output? In this case, all we would do is just _ and then the number of the output, say 2. This should give us 2. So this gives you a more convenient way to access historical commands and their outputs.
Another advantage of Jupyter Notebooks is that you can see images. For example, let's get Matplotlib running. First we're going to import Matplotlib with the following command:
import matplotlib.pyplot as plt
After we've imported Matplotlib, recall that we need to run a certain magic, the Matplotlib magic:
%matplotlib inline
We need to give it the inline parameter, and now we can create a Matplotlib figure. Notice that the image shows up right below the command. When we type in _8, it shows that a Matplotlib object was created, but it does not actually show the plot itself. As you can see, we can use the Jupyter console in a more advanced way than the typical Python console. For example, let's work with a dataset called Iris; import it using the following line:
from sklearn.datasets import load_iris
This is a very common dataset used in data analysis. It's often used as a way to evaluate training models. We will also use k-means clustering on this:
from sklearn.cluster import KMeans
The load_Iris function isn't actually the Iris dataset; it is a function that we can use to get the Iris dataset. The following command will actually give us access to that dataset:
iris = load_iris()
Now we will train a k-means clustering scheme on this dataset:
iris_clusters = KMeans(n_clusters = 3, init = "random").fit(iris.data)
We can see the documentation right away when we're typing in a function. For example, I know what the end clusters parameter means; it is actually the original doc string from the function. Here, I want the number of clusters to be 3, because I know that there are actually three real clusters in this dataset. Now that a clustering scheme has been trained, we can plot it using the following code:
plt.scatter(iris.data[:, 0], iris.data[:, 1], c = iris_clusters.labels_)