I am currently going through Data Driven Security by Jacbos and Rudis, and in Chapter 2 of the book they have the following script that is supposed to be ran in the IPython Console and produce a histogram:
ProductName: Mac OS X
ProductVersion: 10.14
BuildVersion: 18A391
Darwin Kernel Version 18.0.0
Pandas - v0.23.1-4
Numpy - v.1.15.4-1
import pandas as pd
import numpy as np
np.random.seed(1492)
test_df = pd.DataFrame({ "var1": np.random.randn(5000) })
test_df.hist()
The setup instructions suggest using Canopy over pip, which I have attempted to setup using both options to download/update appropriate libraries. When I attempt to execute the code in my Canopy environment, it appears to work as I am not receiving an error, but there is no output (expecting a Histogram).
Welcome to Canopy's interactive data-analysis environment!
Kernel running in the 'User' environment.
Pylab is active using TkAgg.
Python 3.5.2 |Enthought, Inc. (x86_64)| (default, Mar 2 2017, 08:29:05)
Type "copyright", "credits" or "license" for more information.
IPython 5.6.0 -- An enhanced Interactive Python.
%run -i "/Users/john/Desktop/test.py"
%run "/Users/john/Desktop/test.py"
%run -i "/Users/john/Desktop/test.py"
I've been trouble shooting for days and can't seem to figure out why I have do not have the appropriate output. I have attempted running both Py3 and 2.7 but no avail. I have installed and uninstalled Python, and still nothing.
If anyone can recommend or suggest any help I would be very appreciative!
If you are working interactively at the Python prompt (in Canopy's default IPython pylab mode), then those commands will work as-is. Otherwise, such as running a script, as you are, you should also include these commands:
import matplotlib.pyplot as plt
plt.show()
On Python 3, I would also recommend installing the PyQt package in the Canopy Package Manager. See this article: "Python 3 in Canopy 2 - Plotting fails, perhaps with 'No module named PyQt4'"