Lately, I’ve been learning how to take advantage of dictionaries in Python to store and organize information. Dictionaries have a lot of different purposes in Python, but as it applies to data visualization, it can be extremely helpful. Simply put, dictionaries allow us to store almost limitless amounts of information about whatever we want, and then call it when we’re writing our programs or creating visualizations. Doing this allows us to model real-world information more accurately, whether it is storing information about a person’s information, statistics about sports, econometric data, and so on. Another beautiful thing about dictionaries is that they’re easy to manipulate. Rather than using variables for everything, we can sort, loop, or write functions using dictionary values. We can even create other lists of dictionaries. The example below shows how we can create a dictionary where the values are lists, and then cycle through the lists to create messages about each person’s favorite language. Yes, I realize it’s a bit weird just to post a screenshot of my code. However, it seems like a pretty intense process to show an iPython notebook in WordPress. (Edit: Updated the post to show iPython notebook)
Another example of using dictionaries is the basketball data I analyzed for an introductory course I took. The course was called “Python A-Z: Python for Data Science” and I found it through Udemy. We stored each player’s statistics for the past five years into dictionaries and then were able to call upon them way further down the script to run some analysis. Below you’ll see just one of the visualizations I was able to create using dictionaries for organizing the data, NumPy for the statistical functions we needed to run, and Matplotlib for the visualization part. Watch out for another post on Matplotlib and Seaborn shortly.