Load password protected Excel files into Pandas DataFrame

When trying to read an Excel file into a Pandas DataFrame gives you the following error, the issue might be that you are dealing with a password protected Excel file. pd.read_excel(PATH) [...] XLRDError: Can't find workbook in OLE2 compound document There seems to be no way of reading password protected files with xlrd. xlwings for the rescue Fortunately, there is xlwings, which lets you interact with the Excel application itself (via pywin32 or appscript). ...

February 21, 2018 · David Hamann

Bokeh plots with Flask and AJAX

During the weekend, I discovered Bokeh, a Python visualization library for the web. The samples looked nice, so I played around a bit, mostly following the accessible Quick Start guide. Eventually, I decided to build a small dashboard with Bokeh for an existing Flask application and wanted the plots to automatically fetch data updates using AJAX requests. This meant fiddling around a bit and reading more documentation. If you plan on doing something similar, the following write-up hopefully saves you some time and pitfalls. ...

February 11, 2018 · David Hamann

The basics of Logarithms – with examples

Logarithms are widely used in computer science (e.g. for algorithm analyses, floating point number limitations, scaling data, feature transformations). Not coming from a mathematics background (I don’t!) logarithms can seem confusing at first. Let’s look at the very basics of logarithms to get an understanding of how they can be broken apart, some of the properties that can be utilized, and why they work. What is a Logarithm? $$\log_{b}(x)$$The logarithm is defined as the inverse operation to exponentiation. To get the logarithm of a number, we need to find out, to what exponent another number, called the base, needs to be raised to produce that first number. ...

February 6, 2018 · David Hamann

Using vi commands in your bash shell

Entering a long shell command and then moving the cursor around to correct parts of it always felt a bit clunky to me. I remembered some of the <ctrl>/<alt> key bindings but would often just end up using arrow keys or alt-click to navigate to a certain position. Today I learned that you can easily get a vi-style command line interface in bash, giving you insert and normal mode and allowing you to use a basic subset of vi commands. ...

January 28, 2018 · David Hamann

Count elementwise matches for two NumPy arrays

Let’s say we have two integer NumPy arrays and want to count the number of elementwise matches. Here are our two arrays (NumPy imported as np): >>> a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> b = np.array([1, 2, 2, 2, 5, 6, 7, 9, 9]) To create a third (boolean) array that contains True for a match, and False otherwise, we can use the equality operator. >>> a == b array([ True, True, False, False, True, True, True, False, True]) Given that, counting the number of matches is as easy as: >>> np.count_nonzero(a==b) 6 (Another option would be to use the (slower) np.sum(a==b))

January 26, 2018 · David Hamann