Practical Business Python

Taking care of business, one python script at a time

Mon 26 March 2018

Overview of Pandas Data Types

Posted by Chris Moffitt in articles   

When doing data analysis, it is important to make sure you are using the correct data types; otherwise you may get unexpected results or errors. In the case of pandas, it will correctly infer data types in many cases and you can move on with your analysis without any further thought on the topic.

Despite how well pandas works, at some point in your data analysis processes, you will likely need to explicitly convert data from one type to another. This article will discuss the basic pandas data types (aka dtypes), how they map to python and numpy data types and the options for converting from one pandas type to another.

Read more...


Tue 20 February 2018

Intro to pdvega - Plotting for Pandas using Vega-Lite

Posted by Chris Moffitt in articles   

Jake VanderPlas covered this topic in his PyCon 2017 talk and the landscape has probably gotten even more confusing in the year since this talk was presented.

Jake is also one of the creators of Altair (discussed in this post) and is back with another plotting library called pdvega. This library leverages some of the concepts introduced in Altair but seeks to tackle a smaller subset of visualization problems. This article will go through a couple examples of using pdvega and compare it to the basic capabilities present in pandas today.

Read more...


Mon 29 January 2018

Building a PDF Splitter Application

Posted by Chris Moffitt in articles   

I recently had the need to take a couple pages out of a PDF and save it to a new PDF. This is a fairly simple task but every time I do it, it takes some time to figure out the right command line parameters to make it work. In addition, my co-workers wanted similar functionality and since they are not comfortable on the command line, I wanted to build a small graphical front end for this task.

One solution is to use Gooey which is a really good option that I cover in my prior article. However, I wanted to try out another library and decided to give appJar a try. This article will walk through an example of using appJar to create a GUI that allows a user to select a PDF, strip out one or more pages and save it to a new file. This approach is simple, useful and shows how to integrate a GUI into other python applications you create.

Read more...


Tue 02 January 2018

Interactive Visualization of Australian Wine Ratings

Posted by Chris Moffitt in articles   

Over on Kaggle, there is an interesting data set of over 130K wine reviews that have been scraped and pulled together into a single file. I thought this data set would be really useful for showing how to build an interactive visualization using Bokeh. This article will walk through how to build a Bokeh application that has good examples of many of its features. The app itself is really helpful and I had a lot of fun exploring this data set using the visuals. Additionally, this application shows the power of Bokeh and it should give you some ideas as to how you could use it in your own projects. Let’s get started by exploring the “rich, smokey flavors with a hint of oak, tea and maple” that are embedded in this data set.

Read more...


Mon 27 November 2017

Using Python’s Pathlib Module

Posted by Chris Moffitt in articles   

It is difficult to write a python script that does not have some interaction with the file system. The activity could be as simple as reading a data file into a pandas DataFrame or as complex as parsing thousands of files in a deeply nested directory structure. Python’s standard library has several helpful functions for these tasks - including the pathlib module.

The pathlib module was first included in python 3.4 and has been enhanced in each of the subsequent releases. Pathlib is an object oriented interface to the filesystem and provides a more intuitive method to interact with the filesystem in a platform agnostic and pythonic manner.

Read more...