The prettiest data …

Mat Plot Lib

Today I was not feeling like studying, which is my usual daily activity for multiple hours. So, I decided to work on a project from the book “PYTHON PLAYGROUND: Geeky Projects for the Curious Programmer.” The book was a download from the Humble Bumble Book Bundle.

Over the past few weeks, I completed Introduction and flat files from DataCamp’s class Importing Data in Python (numpy, pandas, matplotlib), the numpy chapter of Intro to Python for Data Science, and this past weekend I started Dataquest’s Data Analysis With Pandas: Intermediate Class — I have now finished a whopping 5%, but I am on my way!

So, I decided to use some of these libraries to build something. The first chapter of the book has a program that imports data from your iTunes library and manipulates the data to perform various actions. One of the  actions is to pull out the duration of all songs as well as the ratings you have given to the songs, put the songs in one numpy array and the durations in another, and then plot the results using matplotlib.

Along the way, I made a few changes and resolved a few issues. First, I learned about the plistlib, which parses iTunes libraries. Also, the book uses Python 3, so I had to make some changes to make it work in 2.7. In addition, the book has a function that uses command line arguments to help run the program, and I wanted to use it in the -i python interpreter .

The biggest hurdle was the virtual environment: unbeknownst to me until now, there are well documented issues using the matplot library with virtual environments on a Mac. As I kept fixing one problem, another would occur. Eventually, I decided not to run it in a virtual environment, but then I encountered another set of errors, which ultimately were the result of an older version of six (which is a dependency for the matplot library). Once I uninstalled the older version and installed an updated version and then I got this:

Screen Shot 2016-08-22 at 3.48.32 PM

It may not qualify as the most complex set of plots ever put together, but today I am giving them the “prettiest data” award!

Python class on JSON at Noisebridge

I really like Noisebridge, which is a makerspace in the Mission. Periodically, they host a python series on various topics. A new series just started on intermediate python and the topic for the night was using JSON with Python. While JSON (JavaScript Object Notation) is a subset of JavaScript that is used primarily as a way of exchanging data, Python can transmute information to and from JSON using the json library.

The class was a great refresher, and I also learned a lot about JSON itself. For example, to put a quote in JSON, use a backslash> “\””, how to format objects, numbers and more in JSON (the JSON docs have a helpful set of railroad diagrams about this). We learned about unicode (which is base 16 – harkening back to my weekend math lesson converting between binary and decimal) strings versus regular stings in python 2.7 (apparently in python 3.0 everything is a unicode string.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

Up ↑