Google have released a Python to Go transcompiler

Google have released an open source project on GitHub called Grumpy that converts Python to Go, and then compiles it down to native code. It’s an interesting development, but since they won’t be supporting C extension modules (which basically rules out all the scientific and machine learning libraries I use), it means I probably won’t end up using this …

Read More
Excel confusing CSV file with SYLK file

I recently had an interesting experience whilst using pandas to write some data to a CSV file and then opening the file up with Excel to inspect its contents. To my surprise, I received a message from Excel informing me that I was attempting to open something called a ‘SYLK file’.

Read More
Removing webpage newline characters in Python

An issue I recently came across whilst using the Python requests module was that while I was trying to parse HTML text, I couldn’t remove the newline characters ‘ ‘ with strip().

Read More
Multiprocessing in Python

I frequently find myself working with large lists where I need to apply the same time-consuming function to each element in the list without concern for the order that these calculations are made. I’ve written a small class using Python’s multiprocessing module to help speed things up. It will accept a list, break it up …

Read More
Multiple plots in figures with R

The other day I was working with R in a Jupyter Notebook when I discovered that I needed to include multiple figures in the same plot. Surprisingly, R doesn’t include this capability out of the box, so I went searching and found this function that does the job. I’ve included the code below for my …

Read More
Finding rows in dataframe with a 0 value using Pandas

Recently I needed to identify which of the rows in a CSV file contained 0 values. This was interesting because normally I tend to look at this problem within columns rather than rows. Pandas provides a neat solution to this which I’ll demonstrate below using this data as an example: This data frame should look …

Read More
When to use ‘is’ and ‘==’ in Python

One of the things that may seem confusing in Python is how there appears to be two ways to test if variables are the same: ‘==’ and ‘is’: Both comparison methods returned True, so they do the same thing right? Well, not really. To illustrate this, I’ll change the integer value assigned: Now we have …

Read More
Python object ids and mutable types

Did you know that every object in your Python program is given a unique identifier by the interpreter which you can return using the ‘id()’ function? Let’s see what happens when we assign variables to each other in Python and then print out the variable value and object id: Now I am printing out two …

Read More
Positioning a legend outside the figure with Matplotlib and Python

One of the things that has been a little frustrating lately has been what to do if you need a legend for your plot, yet there’s so much content on your plot you need to place it next to the figure, rather than within it.  The standard way to create a plot with the legend …

Read More
Never trust your factors

I recently helped a friend out with a dataset – she was struggling to merge the CSV files from two dataframes in R into one dataframe. I thought this would be quite simple and yet could not get it to work with merge or dplyr – it just kept giving me weird results. The problem was …

Read More